如何清除Android中的通知 [英] How to clear a notification in Android

查看:17
本文介绍了如何清除Android中的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式清除通知?

Is it possible to clear a notification programatically?

我用 NotificationManager 尝试过,但它不起作用.有没有其他办法可以做到?

I tried it with the NotificationManager but its not working. Is there any other way I can do it?

推荐答案

使用以下代码取消通知:

Use the following code to cancel a Notification:

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);

在这段代码中,用于通知的 ID 总是相同的.如果您有不同的通知需要取消,您必须保存用于创建通知的 ID.

In this code there is alway the same id used for notifications. If you have different notifications that need to be canceled you have to save the ids that you used to create the Notification.

这篇关于如何清除Android中的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆