简体   繁体   English

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

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

So I have followed this link to solve my problem.所以我按照这个链接来解决我的问题。 but i think the answer is out dated.但我认为答案已经过时了。 the code is not working.代码不起作用。

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

so this is condition i'm currently using to detect if sound of notification is on or off (where manager is object of NotificationManager class) .所以这是我目前用来检测通知声音是打开还是关闭的条件(其中 manager 是 NotificationManager 类的对象) but it's not working.但它不起作用。

i want to check if sound of notification is on or off.我想检查通知声音是打开还是关闭。 if it is off then notify user to turn it on.如果它关闭,则通知用户将其打开。

thank you for reading谢谢你的阅读

In your below code if user has not specified anything for notification or if he has Higher notification importance: shows everywhere, makes noise and peeks.在您的以下代码中,如果用户没有为通知指定任何内容,或者他具有更高的通知重要性:到处显示,发出噪音和偷看。 Then your soundAllowed is true.那么你的 soundAllowed 是真的。 I think you should remove importance < 0 so you will get this soundAllowed variable only true with user has gave higher importance to notification sounds我认为你应该删除重要性 < 0 这样你就会得到这个 soundAllowed 变量,只有当用户对通知声音给予更高的重要性时才为真

boolean soundAllowed = importance < 0 || importance >= NotificationManager.IMPORTANCE_DEFAULT; // where default value is 3

Please check the values here for more clarity.请检查此处的值以获得更清晰的信息。

https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_NONE https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_NONE

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

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