[英]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.