Jayesh Sojitra Jayesh Sojitra - 1 year ago 120
Android Question

How to remove notification from notification bar programmatically in android?

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);
![enter image description here][1]am.cancel(pi);

But problem is notification which fired already that are not removed from notification bar.

Thanks in advance...

enter image description here

Answer Source

Maybe try this :

NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

OR, you can also do this to cancel all notifications in given context:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download