Android检查是否允许声音通知设置已启用或以编程方式禁用
因此,我已经关注此链接我的问题。但是我认为答案已经过时了。代码不起作用。
int importance = manager.getImportance();
boolean soundAllowed = importance < 0 || importance >= NotificationManager.IMPORTANCE_DEFAULT;
因此,这是我目前用来检测通知声的条件是打开还是关闭(管理器是通知manager类的对象)。但这不起作用。
我想检查通知的声音是打开还是关闭。如果关闭,请通知用户将其打开。
谢谢你的阅读
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). 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的下面代码中,如果用户尚未指定任何通知或更高的通知重要性:在各处显示,发出噪音和窥视。然后,您的声音是真的。
我认为您应该删除重要性&lt; 0因此,您只有用户才能获得此声音变量,这对通知声音具有更高的重视,
请在此处检查值,以更加清晰。
https://develoder.android.com/android.com/reference com/reference/reference/android/android/android/andapp/nopfificaManager# eximplesence_none
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.
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
Please check the values here for more clarity.
https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_NONE