简体   繁体   English

如何删除一个android通知?

[英]how to delete a android notification?

I want to push a notification to the user every X minutes. 我想每隔X分钟向用户发送一条通知。

However if there already exist an unread notification, 但是,如果已经存在未读的通知,

I want to delete it and replace it with a new one. 我要删除它,并用一个新的替换它。 How can I delete? 如何删除?

How can I check how many unread notification my app has already pushed? 如何查看我的应用程序已经推送了多少未读通知?

To replace an existing notification with a new one you should simply post a notification with the same id, this behavior is mentioned in the documentation of NotificationManager 's notify() method. 要将现有通知替换为新通知,您只需发布具有相同ID的通知NotificationManagernotify()方法文档中就提到了此行为。 If you want to just remove a notification, call cancel() providing the id you used to start it. 如果您只想删除通知,请调用cancel()提供您用于启动通知的ID。

Regarding counting the number of notifications your app has sent, I think the best solution would be to just store a counter and increment it once a notification has been sent. 关于计算您的应用程序已发送的通知数,我认为最好的解决方案是仅存储一个计数器,并在发送通知后对其进行递增。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM