From 32e367fabf2c714004e626309b31c07a77564dce Mon Sep 17 00:00:00 2001 From: tianyifeng Date: Tue, 29 Aug 2023 09:07:24 -0700 Subject: [PATCH] Set groupKey for media notification in DefaultMediaNotificationProvider By doing so, the media notification sent from DefaultMediaNotificationProvider won't be auto-grouped (https://developer.android.com/develop/ui/views/notifications/group#automatic-grouping) with the regular notifications sent from the other places in the app. As the result, when the customer attempts to dismiss the regular notifications (by swiping away), the media notification won't be dismissed as being in the same group. Issue: androidx/media#549 PiperOrigin-RevId: 561047571 --- .../media3/session/DefaultMediaNotificationProvider.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/session/src/main/java/androidx/media3/session/DefaultMediaNotificationProvider.java b/libraries/session/src/main/java/androidx/media3/session/DefaultMediaNotificationProvider.java index 19bc2b7dc7..a11aa3d821 100644 --- a/libraries/session/src/main/java/androidx/media3/session/DefaultMediaNotificationProvider.java +++ b/libraries/session/src/main/java/androidx/media3/session/DefaultMediaNotificationProvider.java @@ -237,6 +237,13 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi public static final int DEFAULT_CHANNEL_NAME_RESOURCE_ID = R.string.default_notification_channel_name; + /** + * The group key used for the {@link NotificationCompat.Builder#setGroup(String)} to avoid the + * media notification being auto-grouped with the other notifications. The other notifications + * sent from the app shouldn't use this group key. + */ + public static final String GROUP_KEY = "media3_group_key"; + private static final String TAG = "NotificationProvider"; private final Context context; @@ -385,6 +392,7 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi .setStyle(mediaStyle) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setOngoing(false) + .setGroup(GROUP_KEY) .build(); return new MediaNotification(notificationId, notification); }