Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i Clear notification in button click

Tags:

android

In my project i have notification option.
Can I remove this notification in a button click?? I can cancel notification when click on this notification using the code

    checkin_notification.flags = Notification.FLAG_AUTO_CANCEL;

but i in my application i want to clear notification after showing it. It should be in a button click.

Thanks in advance.

like image 470
anoop Avatar asked Apr 16 '12 08:04

anoop


People also ask

How do you delete old notifications on Android?

Clear All NotificationsSwipe down from the top of the screen. Scroll down to the bottom of the notifications and click Clear All.


2 Answers

To clear all Notification of your Application you can do like,

NotificationManager notificationManager = (NotificationManager) 
                                 getSystemService(Context.
                                                        NOTIFICATION_SERVICE);
notificationManager.cancelAll();

To clear a particular Notification you can do it like,

notificationManager.cancel(notification_id);
like image 200
Lalit Poptani Avatar answered Oct 24 '22 05:10

Lalit Poptani


onButton Click just Write....

mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);

You can see here http://saigeethamn.blogspot.in/2009/09/android-developer-tutorial-for.html and check it ....

and for clear all ...mNotificationManager.cancelAll();

like image 33
Samir Mangroliya Avatar answered Oct 24 '22 05:10

Samir Mangroliya