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.
Thanks in advance...
any options you want to remove from the notification bar. Tap on any of the switches to turn them on or off. This removes these options from the notification bar.
On the “Settings” menu, tap the “Sound & Notification” option, and then scroll down until you see the “App notifications” entry. Tap that. Tap each app to see its notification options. To disable notifications for an app, switch the “Block All” toggle the on position.
It is not possible to disable notifications from other apps. you can only control notifications generated by your own app. Android: is it possible to remove a system-managed notification programmatically? Show activity on this post.
First, press-and-hold on the persistent notification you want to remove. Another option is to swipe the notification left or right, and then tap on the cogwheel icon shown next to it. Next, tap on the switch next to Permanent to disable it, and then press Save.
Maybe try this :
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();
See this link to the documentation : NotificationManager
I believe the most RECENT and UPDATED way of doing (Kotlin and Java) this should be done as:
NotificationManagerCompat.from(context).cancel(NOTIFICATION_ID)
Or to cancel all notifications is:
NotificationManagerCompat.from(context).cancelAll()
Made for AndroidX or Support Libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With