package com.Example4;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class Example4 extends Activity implements OnClickListener {/** Called when the activity is first created. */private Context mContext;private Button showButton, cancelButton;private Notification mNotification;private NotificationManager mNotificationManager;private final static int NOTIFICATION_ID = 0x0001;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);setupViews();}public void setupViews() {mContext = Example4.this;showButton = (Button) findViewById(R.id.show);cancelButton = (Button) findViewById(R.id.cancel);mNotification = new Notification(R.drawable.icon, null, System.currentTimeMillis());mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);showButton.setOnClickListener(this);cancelButton.setOnClickListener(this);}public void onClick(View v) {if (v == showButton) {Intent mIntent = new Intent(mContext, Example4.class);mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);PendingIntent mContentIntent = PendingIntent.getActivity(mContext,0, mIntent, 0);mNotification.setLatestEventInfo(mContext, null, null,mContentIntent);mNotificationManager.notify(NOTIFICATION_ID, mNotification);} else if (v == cancelButton) {mNotificationManager.cancel(NOTIFICATION_ID);}}}

更多相关文章

  1. android MediaPlayer 错误代码(error code)总结
  2. android 源码编译
  3. android GPS定位和卫星个数(源码)
  4. Android中图片的放大和缩小源码
  5. Android:在WebView中获取网页源码
  6. android 源码下载与编译(ubuntu11.04)
  7. MacAndroid源码下载 Android10详解
  8. 最全面的Android资料大全
  9. 我对Android的理解

随机推荐

  1. Android 下的Search
  2. 安卓APP开发中的屏幕适配问题如何解决?
  3. Android开发--NDK之环境搭建
  4. Android的设计与实现:卷I
  5. Android(安卓)界面类 Activity 和 Fragme
  6. Android聊天室(客户端)
  7. 关于FrameLayout布局的位置问题
  8. Android:使用命令行工具adb、mksdcard等
  9. Android的交叉编译工具
  10. (转)android SQLite的使用