Home » Android » android – NotificationListenerService onNotificationPosted() called multiple times for single Notification when it is part of grouped notification

android – NotificationListenerService onNotificationPosted() called multiple times for single Notification when it is part of grouped notification

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to listen to android notification using NotificationListenerService.

I have tested the code with Whatsapp and Hangout notifications.

Scenario 1: 1 Message from 1 User
I receive onNotificationPosted() call once (which is correct)

Scenario 2: 2 Messages from 1 user
I receive onNotificationPosted() call twice accordingly (which is correct) [I get one more which is a grouped notification with the summary text which is same as the text. I ignore this notification manually]

Scenario 3: multiple messages from multiple users
I am receiving onNotificationPosted() call multiple times as per the no. of users (This is not correct).

Example: 4 users have sent 4 messages and New message is received from
the 5th user. I am receiving 5 onNotificationPosted() call (4 for the
older messages and one for the new). The problem is I can’t
distinguish the one which is new.

I have a pebble smartwatch. I noticed that they are showing the correct message. I was wondering if there is a problem with my notification listener service.

I need help on this.

I have already checked below post.
Android NotificationListenerService onNotificationPosted fire twice
But this is a different scenario as one is called for the message and the other is called for the grouped notification, which i am handling manually)

How to&Answers: