如何获取 Android 的通知颜色?

How to get color of notification for Android?

一些通知的小通知图标显示为大图标左下角的徽章(查看第一条、第二条和最后一条通知)。

但是,post-Lollipop,OS 会自动为小图标设置白色滤镜,每当我尝试从我的 NotificationListenerService 中获取它们进行显示时,它们'以白色返回。有什么方法可以提取小图标的背景颜色,或者直接将小图标作为彩色绘图直接获取吗?下面是我的代码,里面只有returns个全白的图标。

public void onNotificationPosted(StatusBarNotification sbn) {
    super.onNotificationPosted(sbn);

    Bundle extras = sbn.getNotification().extras;
    int smallNotiIcon = extras.getInt(Notification.EXTRA_SMALL_ICON);

    //Code to display obtained small icon in an imageView shows up as white
}

可以通过 color public 字段从通知中检索颜色:

Notification notification = sbn.getNotification();
// ARGB color set with the notification
int color = notification.color;

还有 COLOR_DEFAULT 作为通知的默认颜色,您可以使用它来查看是否设置了自定义颜色。