Android prevents multiple updates of the same notification

I do a poll from the server every x minutes to get events that the user is invited to. Let them say that the user has a new invitation and he receives a notification at 10:00. The user never clicks on the notification, and I want the user to not receive another notification after a few minutes with the same information. Basically, I want unique notifications to be displayed only once and to warn the user once.

You would think that this line of code would work the way I want, but it is not.

notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; 

Does anyone have any ideas?

+4
source share
1 answer

I am not sure if your problem is that you see some notifications or just some sounds / vibrations. Two things you need to do:

  • Yes, use Notification.FLAG_ONLY_ALERT_ONCE or NotificationCompat.Builder#setOnlyAlertOnce() , this will prevent sounds and vibrations from occurring when updating a notification
  • To prevent multiple notifications from appearing in the notification area, you need to make sure that when calling NotificationManager#notify(id, builder.build()); id is a constant value that is always the same for this particular event.
+1
source

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


All Articles