Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification dismissed callback?

my app searches for new articles and sends a notification like "5 new articles". However when i send another one, i want to have it update the text to lets say there were 3 new so something like "8 new articles" BUT "3 new articles" if the user has dismissed that previous notification. I hope you get it.

Is there a way to know that notification was dismissed so i can reset the count?

Thanks !

like image 658
urSus Avatar asked Nov 12 '22 21:11

urSus


1 Answers

This is a rather belated answer but I was looking to find out how to do this myself so perhaps it'll be useful to others. In API level 18 the following service was introduced which should make this straightfoward as you can now get a callback whenever a notification is added or removed:

https://developer.android.com/reference/android/service/notification/NotificationListenerService.html

In particular for the original question see the onNotificationRemoved method

The other option mentioned by jpop above is to use the builder's setDeleteIntent method when creating the notification, which will give a callback when the notification is deleted. This would then require you to maintain the state of the existing raised notifications somewhere else as it only tells you when something is added, not removed.

like image 200
Toby Shepheard Avatar answered Nov 15 '22 10:11

Toby Shepheard