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

发布于 2025-02-10 20:01:24 字数 521 浏览 0 评论 0原文

因此,我已经关注此链接我的问题。但是我认为答案已经过时了。代码不起作用。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在您的下面代码中,如果用户尚未指定任何通知或更高的通知重要性:在各处显示,发出噪音和窥视。然后,您的声音是真的。
我认为您应该删除重要性&lt; 0因此,您只有用户才能获得此声音变量,这对通知声音具有更高的重视,

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

请在此处检查值,以更加清晰。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文