android - 如何在android中以编程方式从通知栏中删除通知?

标签 android notifications android-notifications android-pendingintent

任何人都知道我们如何以编程方式从应用程序中删除通知,该通知是使用待定 Intent 调用的。

我曾经使用以下方法取消通知。

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);

但问题是已经触发但未从通知栏中删除的通知。

提前谢谢...

enter image description here

最佳答案

也许试试这个:

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

或者,您也可以这样做以取消给定上下文中的所有通知:

notificationManager.cancelAll();

请参阅此文档链接:NotificationManager

关于android - 如何在android中以编程方式从通知栏中删除通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19268450/

相关文章:

android-notifications - 适用于 Android 11 的 NotificationChannel 的自定义声音不起作用

android - Delphi XE5 从右到左的语言不会像在 android 中那样出现

android - 为什么 Jelly Bean 不在通知中显示第二行?

macos - 右上角通知HUD窗口

ios - 更新字段 - Realm

android - 在 Android 屏幕锁定时显示状态栏通知文本

android - IllegalStateException 查询 SQLite 但仅在某些设备中

android - 使用操作栏时如何隐藏标题栏?

android - 如何在启动另一个 fragment 后将数据​​保存在 fragment 中?

android - Intent 从我的应用程序打开通知 channel 设置