这两个应该是一样的吗? NotificationChannel.setGroup 和 Notification.Builder.setGroup

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

在创建通知渠道时,我通过将它们分配到一个组 (NotificationChannel.setGroup) 来对其进行分类。 稍后,在显示通知时,我使用 Notification.Builder。这里给setGroup方法的值应该和第一个一样才能正常运行吗?

不一定。尽管它们可能在您的业务规则中相关,但渠道组和通知组的使用原因不同。

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.

因此,如果您设置不同的频道组,它们将分别显示在“应用信息”->“通知”中。如果您的应用有多个频道并且您想进一步组织它们,我会说您只需要它。

通知组,您在Notification.Builder.setGroup()中设置的组,用于对通知托盘中的通知进行分组。您可以在 https://developer.android.com/training/notify-user/group.

了解更多信息