5

I am polling from a server every x minutes to get events a user is invited to. Let's say the user has a new invite and gets a notification at 10:00 am. The user never clicks on the notification, and I want to prevent the user from receiving another notification x minutes later with the same information. Basically I want to allow unique notifications to only display once and alert the user once.

You would think this line of code would work do what I want desired, but it does not.

notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;

Anyone have any ideas?

James Fazio
  • 6,370
  • 9
  • 38
  • 47

1 Answers1

5

I'm not certain if your problem is that you are seeing multiple notifications or just multiple sounds/vibrations are happening. Two things you need to do:

  1. Yes use the Notification.FLAG_ONLY_ALERT_ONCE or NotificationCompat.Builder#setOnlyAlertOnce(), this will prevent sounds and vibrations from occurring when you update the notification
  2. To prevent multiple notifications from appearing in the notification area you need to make sure that when you call NotificationManager#notify(id, builder.build()); the id is a consistent value that is always the same for that particular event.
satur9nine
  • 13,927
  • 5
  • 80
  • 123