endowzoner endowzoner - 1 year ago 148
Android Question

How to dismiss notification after action has been clicked

Since API level 16 (Jelly Bean), there is the possibility to add actions to a notification with

builder.addAction(iconId, title, intent);

But when I add an action to a notification and the action is pressed, the notification is not going to be dismissed.
When the notification itself is being clicked, it can be dismissed with

notification.flags = Notification.FLAG_AUTO_CANCEL;



But obviously, this has nothing to with the actions associated to the notification.

Any hints? Or is this not part of the API yet? I did not find anything.

Answer Source

When you called notify on the notification manager you gave it an id - that is the unique id you can use to access it later (this is from the notification manager:

notify(int id, Notification notification)

To cancel, you would call:

cancel(int id)

with the same id. So, basically, you need to keep track of the id or possibly put the id into a Bundle you add to the Intent inside the PendingIntent?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download