首页 > 解决方案 > android,如何找出通知属于哪个频道

问题描述

在 android 应用程序中,当有活动通知时,它可以使用

NotificationManager.getActiveNotifications() 

获取活动通知。

如果应用配置了多个通知组和频道,如何找出活动通知属于哪个频道?

标签: push-notificationandroid-notifications

解决方案


StatusBarNotification[] list = notificationManager.getActiveNotifications();
for(int i=0;i<list.length;i++) {
  StatusBarNotification activeNoti = list[i];
  Notification noti = activeNoti.getNotification();
  //to get channel ID
  String channelId = noti.getChannelId();
}

注意: notificationManager.getActiveNotifications()只会给出您的应用程序构建的通知(它不会返回不是您的应用程序构建的其他通知)


推荐阅读