Android – Execute code when Android notification is canceled

androidnotifications

I've done some searching and have been unable to find anything even closely related.

When a user cancels a notification in Android (by swiping the notification to one side of the screen), does anyone know of clean way to detect this? I think it would be a rather handy feature in an app to be able to cancel a notification and have the app recognize this and mark something as read in the app instead of clicking the notification and opening the app to mark something as read.

Best Solution

Came across this question today. It looks like the second answer has an interesting solution to detect if a notification is still shown or not. This works for pre API 11 devices. Any device running API 11 or newer can use the setDeleteIntent() to fire a PendingIntent when the notification is cleared.