Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a notification in Android

Is it possible to clear a notification programatically?

I tried it with the NotificationManager but its not working. Is there any other way I can do it?

like image 721
rahul Avatar asked Apr 19 '10 06:04

rahul


People also ask

How do I get rid of a notification that won't go away Android?

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.

How do I remove items from my notification bar?

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.


1 Answers

Use the following code to cancel a Notification:

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); 

In this code there is alway the same id used for notifications. If you have different notifications that need to be canceled you have to save the ids that you used to create the Notification.

like image 195
Janusz Avatar answered Oct 10 '22 13:10

Janusz