Since API level 16 (Jelly Bean), it is possible to add actions to notifications with
builder.addAction(iconId, title, intense);
But when I add an action to the notification and that action is pressed, the notification will not close. When the notification itself is clicked, it can be closed with
notification.flags = Notification.FLAG_AUTO_CANCEL; or builder.setAutoCancel(true);
But clearly, this has nothing to do with the action associated with the notification. Any clues? Or is this not part of the API yet? I didn't find anything.
Solution
When you call notify on the notification manager, you give it an id - a unique id that you can use to access it later 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 track that id or maybe put that id in the Bundle that you add to the Intent inside the PendingIntent?