Android 通知用户更新或移除通知
来源:互联网 发布:php replace函数用法 编辑:程序博客网 时间:2024/06/01 09:26
原文地址:http://android.xsoftlab.net/training/notify-user/managing.html#Removing
当需要在不同时段发布同一事件类型的通知时,应当避免创建新的通知。相反的,应当考虑更新原有的通知,比如更改通知的某些值或者添加一些信息给通知。
下面的部分描述了如何更新通知以及如何移除通知。
修改通知
为了设置通知是可以更新的,需要在发布通知时由NotificationManager.notify(ID, notification)
方法指定该通知的ID。为了更新这条通知,需要更新或者创建一个NotificationCompat.Builder对象,并由这个对象构建一个Notification对象,然后将这个通知对象以相同的ID发布出去。
下面的代码段演示了在事件发生时,一条通知将会被用来更新该事件的数目:
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);// Sets an ID for the notification, so it can be updatedint notifyID = 1;mNotifyBuilder = new NotificationCompat.Builder(this) .setContentTitle("New Message") .setContentText("You've received new messages.") .setSmallIcon(R.drawable.ic_notify_status)numMessages = 0;// Start of a loop that processes data and then notifies the user... mNotifyBuilder.setContentText(currentText) .setNumber(++numMessages); // Because the ID remains unchanged, the existing notification is // updated. mNotificationManager.notify( notifyID, mNotifyBuilder.build());...
移除通知
在以下事件发生时,通知将会从通知栏中移除:
用户移除了该通知或者使用了”Clear All”功能(如果通知是可移除的话)。
用户点击了通知,这条通知在创建时使用了setAutoCancel(false)方法(false是默认属性)。
通过调用cancel()方法并指定该通知的ID。这个方法还可以移除进行中的通知。
通过调用cancelAll()方法,将已经发布的所有通知移除。
1 0
- Android 通知用户更新或移除通知
- Android官方开发文档Training系列课程中文版:通知用户之更新或移除通知
- 移除通知
- Android通知图库更新
- Swift中移除通知
- 移除本地所有通知
- 通知未移除崩溃
- Mac NSUserNotification移除通知
- android发送通知及更新通知
- Android创建并更新通知栏通知
- Android 如何通知用户更新app的版本
- Android 如何通知用户更新app的版本
- 通知Android系统相册更新
- Android UI学习 - 用户通知
- Android通知之自定义通知、响应通知上自定义按钮和更新通知的实现
- iOS通知的添加和移除
- 侧滑返回通知被移除
- 通知的具体使用——通知的发送、接受、通知的移除
- java-设计模式-责任链
- 微信序列号生成器架构设计及演变
- 文件内容查阅命令
- iOS笔记--oc语法10(动态类型)
- Basics CSS
- Android 通知用户更新或移除通知
- Java集合框架
- TCP 的三次握手 与 四次挥手详解(转载)
- View 的事件分发机制
- PHP-AES加密解密算法
- Round B APAC Test 2016
- 考研复习第13弹
- 使用lib.exe生成.lib文件
- 关于笔记本键盘错乱的原因及解决办法