简体   繁体   English

如何取消应用程序在后台运行时收到的通知?

[英]how to cancel a notification that received when app run in the background?

the following code works for me when the notification received while the application run on the foreground.当应用程序在前台运行时收到通知时,以下代码适用于我。

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

but when the notification received while the application on the background then it does not work (the specific notification that I try to delete is not deleted).但是当应用程序在后台收到通知时,它不起作用(我尝试删除的特定通知没有被删除)。 cancelAll() functtion delete all background and foreground received notifications but I don't want to use it because I want to delete a specific notification. cancelAll() 函数删除所有后台和前台收到的通知,但我不想使用它,因为我想删除特定的通知。

I am getting notification via FCM(Firebase cloud messaging).我通过 FCM(Firebase 云消息传递)收到通知。

Android 10 Android 10

thank you谢谢你

Use利用

notificationmanger.cancelall(); notificationmanger.cancelall();

That will close tour all notifications from any where so you can create them again i hope its helpful这将关闭来自任何地方的所有通知,以便您可以再次创建它们,我希望它有帮助

Public Int Helpnotification = 6:公共 Int Helpnotification = 6:

Notificationmanger.notify(notification, Helpnotification); Notificationmanger.notify(notification, Helpnotification);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到远程通知时,在后台运行该方法而不启动应用程序 - run the method in background without launching app when remote notification received 如何在应用程序在后台时收到的通知中保存数据 - How to save data from notification received when the app is in the background 如何在收到通知且应用程序处于后台时调用 android 中的另一个活动 - How to call another activity in android when notification received and app is in background 无法“打开”应用在后台时收到的通知 - Cannot "open" notification that is received when the app is in background 收到通知时如何启动后台作业 - how to start background job when a notification received 当应用程序在后台或被杀死时,如何在收到通知时启动我的应用程序或活动? - how can i launch my app or an activity on notification received when app is in background or killed? 应用程序在前台时收到的推送通知与应用程序在后台时收到的推送通知不同 - Push notification received while the app is in the foreground is different from push notification received when the app is in background 在后台收到通知时,如何让我的android应用执行代码? - How can I get my android app to execute code when a notification is received when it's in background? 当用户应用程序在后台运行时如何显示通知? - How to show notification when user app run in background? 当收到Firebase通知且应用程序在后台时显示对话框 - Show a Dialog when Firebase Notification is received and App is in the background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM