简体   繁体   English

android检查是否以编程方式启用了“允许声音”通知设置

[英]android check if "Allow sound" notification setting is enabled programmatically

I am really surprised this question as not been asked yet on SO.我真的很惊讶这个问题还没有被问到。 It's 2020 people.这是2020人。 Our application is trying to gather notification manager information from the phone such as, if notifications are enabled and if sounds are enabled.我们的应用程序正在尝试从手机收集通知管理器信息,例如,是否启用了通知以及是否启用了声音。 Notifications enabled was easy: NotificationManager.areNotificationEnabled , but how do I programmatically check if the Allow sound toggle of the App Notification settings is enabled for our application, as depicted in the following screenshot?启用通知很简单: NotificationManager.areNotificationEnabled ,但是我如何以编程方式检查是否为我们的应用程序启用了应用程序通知设置的Allow sound切换,如下面的屏幕截图所示?

设置

I found out that you can determine this boolean value by checking if the importance value of the notification manager is less than 0 , ie is negative, or is greater than or equal to NotificationManager.IMPORTANCE_DEFAULT :我发现你可以通过检查通知管理器的重要性值是否小于0来确定这个布尔值,即是否为负,或者大于或等于NotificationManager.IMPORTANCE_DEFAULT

NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int importance = manager.getImportance();
boolean soundAllowed = importance < 0 || importance >= NotificationManager.IMPORTANCE_DEFAULT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM