如何在Android中以编程方式从通知栏删除通知? [英] How to remove notification from notification bar programmatically in android?
本文介绍了如何在Android中以编程方式从通知栏删除通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道我们如何以编程方式从应用程序中删除通过Pending intent调用的通知.
Anybody have idea how can we remove notification from application programmatically which is called using Pending intent.
我曾经使用以下方法取消通知.
I have used to cancel notification using following method.
AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(Display.this, TwoAlarmService.class);
PendingIntent pi = PendingIntent.getBroadcast(Display.this, AlarmNumber, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.cancel(pi);
但是问题是已经触发的通知尚未从通知栏中删除.
But problem is notification which fired already that are not removed from notification bar.
预先感谢...
推荐答案
也许试试看:
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);
或者,您也可以执行以下操作来取消给定上下文中的所有通知:
OR, you can also do this to cancel all notifications in given context:
notificationManager.cancelAll();
请参阅此文档链接: NotificationManager
这篇关于如何在Android中以编程方式从通知栏删除通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文