Reputation: 21
I'd tried NotificationListenerService
provided by Android to listen to notifications by using it's OnNotificationPosted()
method. That's all okay. How to detect a change in that notification?
For example: In WhatsApp, if a message is sent and then deleted, It removes the existing notification and sends a new notification as "This message was deleted". So how to detect that which notification gets changed or updated?
Upvotes: 1
Views: 506
Reputation: 41
Are you receiving the "changed" notification in onNotificationPosted()? As far as I understand, the notification is replaced instead of changed. So the changes may register as a newly arrived notification.
Update: it turns out "updating" the notification is indeed pushing a new notification but with the same id. So simply track the id of the notification to see which notification was updated. In your notification listener onNotificationPosted()
public void onNotificationPosted(StatusBarNotification sbn)
{
//this is the notification id
int id = sbn.getId();
...
}
Upvotes: 1