Android notification dismissed callback?
Asked Answered
P

3

7

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 !

Pyles answered 26/9, 2012 at 22:10 Comment(1)
The solution to your problem is found over at #14671953 (probaby too late for you, left here for the benefit of those seeking a solution in the future - Hi, people from the future!)Capello
B
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.

Bridget answered 28/11, 2014 at 20:14 Comment(0)
D
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

Daily answered 26/9, 2012 at 23:10 Comment(2)
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 beforePyles
@VlastoBennyLava #3957919 I don't have any idea about ICS swipe-to-dismiss.Daily
T
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

Tallulah answered 9/3, 2018 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.