user533844
user533844

Reputation: 2063

Android cancel notification

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 ?

Upvotes: 7

Views: 13935

Answers (1)

sarath
sarath

Reputation: 3201

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.

Upvotes: 18

Related Questions