Jayesh Sojitra Jayesh Sojitra - 1 year ago 174
Android Question

How to remove notification from notification bar programatically in android?

Any body 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


Maybe try this :

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

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