我在状态栏中显示一个图标。现在我想在打开该内容时立即删除该图标,一段时间后如果我们收到任何警报,该图标将再次显示。我怎样才能做到这一点?
使用NotificationManager取消您的通知。您只需提供您的通知 ID。
https://developer.android.com/reference/android/app/NotificationManager.html https://developer.android.com/reference/android/app/NotificationManager.html
private static final int MY_NOTIFICATION_ID= 1234;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(MY_NOTIFICATION_ID, notification);
示例代码不完整。这取决于您如何创建通知。
只需确保您使用与创建通知时相同的 ID 来取消通知即可。
取消:
mNotificationManager.cancel(MY_NOTIFICATION_ID);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)