Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Create a Group of Notifications

Starting in Android 7.0 (API level 24), you can display related notifications in a group (previously called "bundled" notifications). For example, if your app shows notifications for received emails, you should put all notifications into the same group so they can be collapsed together.

To support older versions, you can also add a summary notification that appears alone to summarize all the separate notifications—this is often best done with the inbox-style notification.

Figure 1. A collapsed and expanded notification group

You should use notification groups if all of the following conditions are true for your use case:

  • The child notifications are complete notifications and can be displayed individually without the need for a group summary.
  • There is a benefit to surfacing the child notifications individually. For example:
    • They are actionable, with actions specific to each notification.
    • There is more information in each notification that the user should see.

If your notifications don't meet the above criteria, you should instead consider updating an existing notification with new information or create a message-style notification to show multiple updates in the same conversation.

Create a group and add a notification to it

To create a notification group, define a unique identifier string for the group. Then, for each notification you want in the group, just call setGroup(), passing the group name. For example:


Notification newMessageNotification = new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)

By default, notifications are sorted according to when they were posted, but you can change order by calling setSortKey().

If alerts for a notification's group should be handled by a different notification, call setGroupAlertBehavior(). For example, if you want only the summary of your group to make noise, all children in the group should have the group alert behavior GROUP_ALERT_SUMMARY. The other options are GROUP_ALERT_ALL and GROUP_ALERT_CHILDREN.

Set a group summary

On Android 7.0 (API level 24) and higher, the system automatically builds a summary for your group using snippets of text from each notification. The user can expand this notification to see each separate notification, as shown in figure 1. To support older versions, which cannot show a nested group of notifications, you must create an extra notification that acts as the summary. This appears as the only notification and the system hides all the others. So this summary should include a snippet from all the other notifications, which the user can tap to open your app.

To add a group summary, proceed as follows:

  1. Create a new notification with a description of the group—often best done with the inbox-style notification.
  2. Add the summary notification to the group by calling setGroup().
  3. Specify that it should be used as the group summary by calling setGroupSummary(true).

For example:

//use constant ID for notification used as group summary
int SUMMARY_ID = 0;

Notification newMessageNotification1 =
    new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
        .setContentText("You will not believe...")

Notification newMessageNotification2 =
    new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
        .setContentText("Please join us to celebrate the...")

Notification summaryNotification =
    new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
        //set content text to support devices running API level < 24
        .setContentText("Two new messages")
        //build summary info into InboxStyle template
        .setStyle(new NotificationCompat.InboxStyle()
                .addLine("Alex Faarborg  Check this out")
                .addLine("Jeff Chang    Launch Party")
                .setBigContentTitle("2 new messages")
        //specify which group this notification belongs to
        //set this notification as the summary for the group

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(emailNotificationId1, newMessageNotification1);
notificationManager.notify(emailNotificationId2, newMessageNotification2);
notificationManager.notify(SUMMARY_ID, summaryNotification);

The summary notification ID should stay the same so that it is only posted once, and so you can update it later if the summary information changes (subsequent additions to the group should result in updating the existing summary).