7

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 ?

user533844
  • 2,053
  • 7
  • 36
  • 43
  • possible duplicate of [How to clear a notification in android](http://stackoverflow.com/questions/2665634/how-to-clear-a-notification-in-android) – rds Apr 15 '13 at 13:46
  • I believe that [this](http://stackoverflow.com/questions/2665634/how-to-clear-a-notification-in-android) post will answer your question. It discusses how to clear notifications. – Nick Oct 25 '11 at 18:40
  • possible duplicate of [Android: remove notification from notification bar](http://stackoverflow.com/questions/3595232/android-remove-notification-from-notification-bar) – Zach Saucier Jan 19 '15 at 07:28
  • Show your code for notification – Atul O Holic Jan 19 '15 at 12:21

1 Answers1

18
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.

sarath
  • 3,181
  • 7
  • 36
  • 58
  • If possible can you answer this question as well? It is not working for me on Android 10. [Click here for the question](https://stackoverflow.com/q/61478154/5716010) – Maulik Dodia Apr 28 '20 at 10:40