Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute code when Android notification is canceled [duplicate]

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.

like image 652
Luke Avatar asked Apr 18 '12 06:04

Luke


2 Answers

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.

like image 193
Luke Avatar answered Sep 25 '22 11:09

Luke


Luke's answer helped me with this. Thanks!

I also found this setDeleteIntent() example which I share for everyone's reference.

how to use delete intent to perform some action on clear notification?

like image 34
Anthony De Souza Avatar answered Sep 23 '22 11:09

Anthony De Souza