Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android cancel notification

Tags:

android

I have a background service running to get data. I check for new data and send status bar notification. Sending notification is part of the service. When user sees that notification, he logs on to the application and accepts it. That time I want to delete it from status bar. Can I do that ?

like image 635
user533844 Avatar asked Oct 25 '11 18:10

user533844


People also ask

How do I dismiss notifications on Android?

To dismiss a notification, touch it and swipe left or right. Tap the dismiss icon to dismiss all notifications. On newer versions of Android, you can manage some notifications from the lock screen. Double-tap a notification to open the app or swipe left or right to dismiss the notification.

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

To remove a persistent notification on Android as fast as possible, first, press-and-hold on it. Alternatively, swipe the notification left or right to reveal a gear icon on either side, and then tap on it. The notification expands. Tap on “Turn off notifications” at the bottom.

How do I get rid of a notification I don't want?

Check your app notification settings Go to your profile picture . Tap Notifications. Tap the sliders to turn off notification options.


1 Answers

if (Context.NOTIFICATION_SERVICE!=null) {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(ns);
        nMgr.cancel(0);
    }

write the above code in the second class and create the notifications in the first class using the id 0.

like image 65
sarath Avatar answered Oct 26 '22 09:10

sarath