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...
All notifications (even other app notifications) can be removed via listening to 'NotificationListenerService' as mentioned in NotificationListenerService Implementation
In the service you have to call
cancelAllNotifications()
.The service has to be enabled for your application via ‘Apps & notifications’ -> ‘Special app access’ -> ‘Notifications access’.
Add to manifest:
Then in code;
After that use the broadcast receiver to trigger the clear all.
Maybe try this :
OR, you can also do this to cancel all notifications in given context:
See this link to the documentation : NotificationManager
Notifications remain visible until one of the following happens:
The user dismisses the notification either individually or by using "Clear All" (if the notification can be cleared). The user clicks the notification, and you called setAutoCancel() when you created the notification. You call cancel() for a specific notification ID. This method also deletes ongoing notifications. You call cancelAll(), which removes all of the notifications you previously issued. If you set a timeout when creating a notification using setTimeoutAfter(), the system cancels the notification after the specified duration elapses. If required, you can cancel a notification before the specified timeout duration elapse