10

I have an app where the user can receive multiple notifications for things they need to do. The user has a choice of making some of these notifications persistent (which I achieve by calling NotificationCompat.Builder.setOngoing). At least on my version of Android which is Nougat, when more than three notifications are posted by my app they get bundled together into one notification, which makes all of them dismissible to the user in one swipe. This makes the previously persistent notifications no longer persistent. Is there a way to programmatically instruct Android not to bundle my notifications?

This is the code I use to build the notification and display it:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle(eventName + " " + notificationText)
        .setDefaults(Notification.DEFAULT_ALL)
        .setOnlyAlertOnce(true)
        .setContentIntent(eventListPendingIntent);

if (goalInfo.goal.persistNotification) {
    builder.setOngoing(true);
} else {
    builder.setAutoCancel(true);
}

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(eventType.value(), builder.build());

Thanks, Nir

Nir Arbel
  • 215
  • 1
  • 3
  • 11
  • Can you paste your code snippet because bundling is not done by default. You must be doing something which you clearly should not to avoid bundling – Dibzmania Feb 11 '17 at 01:11
  • I added the code to my question. It only bundles them if there are more than three notifications... – Nir Arbel Feb 11 '17 at 08:45

1 Answers1

16

As per Google docs, notifications from the same app would be bundled automatically -

Note: If the same app sends four or more notifications and does not specify a grouping, the system automatically groups them together.

So in your case, what you can do is , instead of system applying the default grouping, you can separate your notifications into two groups using a separate group key for the persistent notifications and one for the non-persistent ones.

Check the Google docs. The method Builder.setGroup() on NotificationBuilderCompat takes a string parameter which is the key. There is a related method Builder.setGroupSummary which you should call on your Builder

Hope this is clear.

Dibzmania
  • 1,934
  • 1
  • 15
  • 32