如何在android中以编程方式从通知栏中删除通知? [英] How to remove notification from notification bar programmatically in android?

查看:28
本文介绍了如何在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屋!

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