如何检查用户是否禁用了通知声音?

How to check if user have disabled sounds for notifications?

在Android7中,您可以长按一个通知,然后选择让所属应用的通知无声显示。

对于 Android 7,我们有 NotificationManager.areNotificationsEnabled() 检查用户是否屏蔽了您应用的通知。 如何检查用户是否刚刚关闭了应用程序通知的声音?

更新: 问题仍然代表Android 8/O。我们有一些用户抱怨没有听到任何声音,然后他们在不知情的情况下禁用了它,而我们也没有机会检查它。

声音在 IMPORTANCE_DEFAULT 及以上启用,因此您可以这样检查:

@RequiresApi(26)
private boolean hasSoundsEnabled(String channelId) {
    NotificationManager manager = getSystemService(NotificationManager.class);
    NotificationChannel channel = manager.getNotificationChannel(channelId);

    return channel.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT;
}