简体   繁体   中英

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) . 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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