Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification Group not working without summary

I am implementing notifications and want to group them for display in notification bar.

Currently I am implementing the example from Create a Group of Notifications in Android's official developer documentation.

I implemented this method:

private void makeNotification()
{
    createNotificationChannel();

    int SUMMARY_ID = 0;
    String GROUP_KEY_WORK_EMAIL = "com.android.example.WORK_EMAIL";
    String CHANNEL_ID = "MY_CHANNEL_ID";

    Notification newMessageNotification1 =
            new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
                    .setSmallIcon(R.drawable.ic_map_position_icon)
                    .setContentTitle("First summary")
                    .setContentText("You will not believe...")
                    .setGroup(GROUP_KEY_WORK_EMAIL)
                    .build();

    Notification newMessageNotification2 =
            new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
                    .setSmallIcon(R.drawable.ic_map_nav_position_icon_grey)
                    .setContentTitle("Second summary")
                    .setContentText("Please join us to celebrate the...")
                    .setGroup(GROUP_KEY_WORK_EMAIL)
                    .build();

    Notification summaryNotification =
            new NotificationCompat.Builder(MainActivity.this, CHANNEL_ID)
                    .setContentTitle("Total summary")
                    .setContentText("Two new messages")
                    .setSmallIcon(R.drawable.ic_wdw_dont_drive)
                    .setGroup(GROUP_KEY_WORK_EMAIL)
                    .setGroupSummary(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    notificationManager.notify(1, newMessageNotification1);
    notificationManager.notify(2, newMessageNotification2);
    notificationManager.notify(SUMMARY_ID, summaryNotification);
}

The method createNotificationChannel()just creates the channel, I left it out here for better readability.

Now the documentation says:

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.

So the last notify() call shall be optional and creating the summaryNotification, too. But this example only works for me when I notify the summary notification. When I don't do that, the notifications are not grouped.

What is going wrong here?

like image 424
unlimited101 Avatar asked Sep 25 '18 12:09

unlimited101


1 Answers

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.

"Summary [text]" but not "Group summary notification". This just means that whatever text you set in summary notification style it will be replaced by combined text from grouped notifications for Android >= N.

This doesn't affect the fact that the notifications are not grouped without summary.

Yes, this was highly misleading for me too, had to learn it the hard way. Try building the group on Kitkat and compare it to Nougat one.

like image 141
Kanedias Avatar answered Oct 20 '22 14:10

Kanedias