Search code examples
androidnotificationsheads-up-notifications

Can an Android heads up notification be shown more than one time without user cancel?


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?


Solution

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