AljoSt
AljoSt

Reputation: 439

Remove notifications from tray

How can I remove all notifications in the notification tray that were sent by my server when the user clicks on one notifiaction?

I have a chatting-app and the user gets a notification for each message (if the app is not in foreground). When the user clicks on one of those notifications the app will be brought to foreground / will be started. After that has happened, I want all other notifications in the notification bar to disappear as well.

Upvotes: 0

Views: 1224

Answers (2)

Hisham Muneer
Hisham Muneer

Reputation: 8742

No, you dont have to save the ids of all notifications, you can simply call:

NotificationManager nManager = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)); 
nManager.cancelAll();

Upvotes: 1

Abdul Momen Khan
Abdul Momen Khan

Reputation: 319

Use the following code to cancel a Notification:

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

If you have different notifications that need to be canceled you have to save the ids that you used to create the Notification.

Upvotes: 0

Related Questions