0

My app targets:

minSdkVersion 21
targetSdkVersion 25

I am able to display a heads-up notification with this:

NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(activity)
            .setPriority(Notification.PRIORITY_MAX)
            .setAutoCancel(true);
notificationBuilder.setVibrate(new long[0]);
((NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify(9999, notificationBuilder.build());

When the app tries to display another heads-up notification with the same ID but a different message, the notification is updated but is not shown as a new heads-up notification. The notification is not displayed again over top of the app.

Is it possible to show a heads-up notification with the same ID twice without the user cancelling the first notification?

Lou Morda
  • 5,078
  • 2
  • 44
  • 49
  • 4
    why not just cancel the notification before showing the new one? – tyczj Jul 17 '17 at 18:26
  • I tried that and am getting weird behavior. The notification icon disappears, and then reappears with the new message, but does not show heads-up! I tried .cancel() with the ID and also .cancelAll() – Lou Morda Jul 17 '17 at 20:01

1 Answers1

2

I think the setOnlyAlertOnce() method is what you are looking for.

kws
  • 926
  • 7
  • 11