Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if user have disabled sounds for notifications?

In Android 7 you can long click a notification and choose to that notifications from the belonging app should be displayed without sounds.

For Android 7 we have NotificationManager.areNotificationsEnabled() to check if user have blocked the notifications for your app. How do you check if the user have just disabled the sounds for the notifications for the app?

Update: The question still stands for Android 8/O. We have a few users who complain about not hearing any sounds and then they have disabled it without knowing it and without us having a chance to check it.

like image 492
Roy Solberg Avatar asked Sep 21 '16 13:09

Roy Solberg


People also ask

How do I check my notification sounds?

Open your device's Settings app . Tap Accessibility. Sound Notifications. Tap Open Sound Notifications.

Why do my notifications not have sound?

Try these steps: Go to Settings > Sound & Notification > App Notifications. Select the app, and make sure that Notifications are turned on and set to Normal. Make sure that Do Not Disturb is turned off.

How do I turn off sound for notifications?

Tap Settings. . Tap Notifications. Turn Disable sounds & vibrations on or off.


1 Answers

Sounds are enabled at IMPORTANCE_DEFAULT and upwards, so you can check like this:

@RequiresApi(26)
private boolean hasSoundsEnabled(String channelId) {
    NotificationManager manager = getSystemService(NotificationManager.class);
    NotificationChannel channel = manager.getNotificationChannel(channelId);

    return channel.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT;
}
like image 172
Florian Walther Avatar answered Nov 15 '22 00:11

Florian Walther