Android NotificationListenerService onNotificationPosted fire twice

后端 未结 5 953
情深已故
情深已故 2021-01-18 12:35

I listen for notifications like WhatsApp Messages.

But every time a notification comes in the NotificationListenerService fire twice.

Does anyone know this p

5条回答
  •  爱一瞬间的悲伤
    2021-01-18 13:20

    This issue happened to me too. My workaround is to use notification's time + (notification's title + notification's text) as two keys.

    If time is not older than 1 sec and similar title + text then ignore.

    if (Calendar.getInstance().getTimeInMillis() - lastMessageTime < 1000 && lastMessageContent.equalsIgnoreCase(title + text)) {
            // Ignore
            return;
        } else {
            lastMessageContent = title + text;
            lastMessageTime = Calendar.getInstance().getTimeInMillis();
        }
    

    I worked for me but I think it may missed some notification.

提交回复
热议问题