I create several notifications like this:
public class NotificationCreator {
Context context;
int c = 0;
public NotificationCreator(final Context context) {
this.context = context;
}
void create() {
String text = "" + c + " " + new Date().toGMTString();
// Intent
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra(SecondActivity.KEY, text);
Intent[] intents = new Intent[1];
intents[0] = intent;
PendingIntent pendingIntent = PendingIntent.getActivities(
context,
c,
intents,
PendingIntent.FLAG_CANCEL_CURRENT);
// Build notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.notification);
builder.setContentTitle("Test");
builder.setContentText(text);
// builder.setGroup("");
builder.setContentIntent(pendingIntent);
Notification notification = builder.build();
// Send notification
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(c, notification);
c++;
}
}
The outcome on Android 7 is:
The system has grouped all notifications.
When I set explicitly on the builder:
builder.setGroup("myGroup");
the outcome is:
The notifications are not grouped, but all shown individually, despite all having the same group key.
Is this the expected behaviour?
In the first case (grouped), can I determine what happens when the user clicks on the grouped notification? The individual intents seem to be ignored and just the app opened.
Starting in Android 7.0 (API level 24), you can choose to 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.
The user can tap the group summary notification to open your app. On Android 7.0 and higher, the system shows your group summary notification as a nested group of notifications, labeled with snippets of text from each grouped notification; it does not display the text you set on the group summary notification.
Notification categories are an Android Oreo (8.0+) feature which gives users finer control over notifications. When the user receives a notification with a category they can long press on it or go into the Notification Settings to change the category's settings.
Introduced in iOS 12, Notification Grouping does basically what the name implies. Rather than every single notification showing up on the lock screen and Notification Center separately, they can be grouped into bundles.
Had the same problem and figured it out by using a "Summary notification". Basically, you create one regular notification with the desired group and the "Summary notification" with the same group and setGroupSummary(true)
.
More here https://blog.stylingandroid.com/nougat-bundled-notifications/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With