NotificationListenerService onNotificationPosted (), called multiple times for a single notification when it is part of a grouped notification

I am trying to listen for an android notification using NotificationListenerService.

I checked the code with Whatsapp and Hangouts notifications.

Scenario 1: 1 Message from 1 user I get onNotificationPosted () once (which is correct)

Scenario 2: 2 Messages from 1 user I get onNotificationPosted () two times respectively (which is correct) [I get another one, which is a grouped notification with the resulting text that matches the text. I ignore this notification manually]

Scenario 3: multiple messages from multiple users I receive an onNotificationPosted () call several times according to no. users (this is incorrect).

Example: 4 users sent 4 messages and received a new message from the 5th user. I get 5 calls onNotificationPosted () (4 for older posts and one for new). The problem is that I cannot distinguish the new.

I have a pebble smartwatch. I noticed that they show the correct message. I was wondering if there was a problem with my notification listening service.

I need help with this.

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

+5
source share

Source: https://habr.com/ru/post/1246471/


All Articles