android之Notification的使用
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一样。
这也就完成了,添加删除工作。
更多相关文章
- Android8.0通知适配
- Android(安卓)2.1 GPS定位和拍照功能代码
- android 获取和设置屏幕亮度
- ListView 实现像Android(安卓)Market那样 分页加载 滚动加载
- android6.0 netd设置dns
- Android(安卓)开发常用代码片段
- Ubuntu 下开发 Android(安卓)环境变量设置
- 设置默认来电铃声 android
- Gps简单更新