Search code examples
androidpush-notificationandroid-8.0-oreoandroid-9.0-pie

Should these two be the same? NotificationChannel.setGroup and Notification.Builder.setGroup


While creating notification channels, I categorise them by assigning them to a group (NotificationChannel.setGroup). Later, while displaying notification, I use Notification.Builder. Should the value given to setGroup method here be the same as the first to function properly?


Solution

  • Not necessarily. Even though they might be related in your business rules, channel groups and notification groups are used for different reasons.

    As stated in https://developer.android.com/training/notify-user/channels:

    If you'd like to further organize the appearance of your channels in the settings UI, you can create channel groups. This is a good idea when your app supports multiple user accounts (such as for work profiles), so you can create a notification channel group for each account. This way, users can easily identify and control multiple notification channels that have identical names.

    So, if you set different channel groups they'll be displayed separately in App Info -> Notifications. I'd say you just need it if your app has multiple channels and you want to further organize them.

    A notification group, the one you set in Notification.Builder.setGroup(), is used to group notifications in the notification tray. You can learn more about it at https://developer.android.com/training/notify-user/group.