【问题标题】:How to check if user have disabled sounds for notifications?如何检查用户是否禁用了通知声音?
【发布时间】:2016-09-21 13:46:19
【问题描述】:

在 Android 7 中,您可以长按一个通知并选择该应用程序的通知应该在没有声音的情况下显示。

对于 Android 7,我们有 NotificationManager.areNotificationsEnabled() 来检查用户是否阻止了您应用的通知。 如何检查用户是否刚刚禁用了应用通知的声音?

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

【问题讨论】:

    标签: android android-notifications


    【解决方案1】:

    在 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      • 2020-04-27
      相关资源
      最近更新 更多