5

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 !

urSus
  • 12,492
  • 12
  • 69
  • 89
  • 4
    The solution to your problem is found over at http://stackoverflow.com/questions/14671453/catch-on-swipe-to-dismiss-event (probaby too late for you, left here for the benefit of those seeking a solution in the future - Hi, people from the future!) – jpop Oct 15 '14 at 08:48

3 Answers3

1

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.

0

If your app has a database you can do this: Create a table that has some fields like id as int, article name as string, and isdismissed as boolean. So, each time you want to send a notification, you should count the records that the isdismissed field equals false. In the other hand, each time user select a notification, the related isdismissed field must be equal true.

In addition, this sample from developer.android.com maybe can help you:

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Behzad
  • 1,740
  • 1
  • 22
  • 49
  • yeah, but how do i know that user has selected the notification? Now when i think about it when user click on it and intent is fired so maybe i could do it there, i was thinging more about the ICS swipe-to-dismiss notification callback before – urSus Sep 26 '12 at 23:28
  • @VlastoBennyLava http://stackoverflow.com/questions/3957419/android-status-bar-notification I don't have any idea about ICS swipe-to-dismiss. – Behzad Sep 27 '12 at 07:32
0

the listener don't work since android Nougat, a new access rule have been added

on android device : parameters -> applications -> gear menu -> spécial access -> notifications access

use : catch on swipe to dismiss event