1:获取NotificationManager:
NotificationManager m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
2:定义一个Notification:
Notification m_Notification=new Notification();
3:设置Notification的各种属性:
//设置通知在状态栏显示的图标
m_Notification.icon=R.drawable.icon;
//当我们点击通知时显示的内容
m_Notification.tickerText="Button1 通知内容.....";
通知时发出的默认声音
m_Notification.defaults=Notification.DEFAULT_SOUND;
//设置通知显示的参数
Intent m_Intent=new Intent(NotificationDemo.this,DesActivity.class);
PendingIntent m_PendingIntent=PendingIntent.getActivity(NotificationDemo.this, 0, m_Intent, 0);
m_Notification.setLatestEventInfo(NotificationDemo.this, "Button1", "Button1通知",m_PendingIntent );
//这个可以理解为开始执行这个通知
m_NotificationManager.notify(0,m_Notification);
4:既然可以增加同样我们也可以删除。当然是只是删除你自己增加的。
m_NotificationManager.cancel(0);
这里的0是一个ID号码,和notify第一个参数0一样。
这也就完成了,添加删除工作。