How to detect a change in Notification (Status bar notification) in Android

478 views Asked by At

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?

1

There are 1 answers

0
Valkriaine Wayne Wang On

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();
     ...
 }