forgemo forgemo - 1 year ago 85
Android Question

How to mute sound and vibration for all notifications in Android 5.0+?

I would like to disable sound and vibration for all incoming notifications. I don't mind if phone call vibration gets switched off, too. But the users volume settings for phone calls shouldn't be touched.

Thanks to the AudioManager, muting the sound of notifications is easy:

audioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);

Disabling the vibration of notifications, however, is harder than expected.

The AudioManager has this deprecated method for vibration settings:

audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF)

This, however, seems to have no effect on my Android 5.0 device and I can't find any alternatives. :(

I know that Lollipop has introduced the stuff around "Priority Mode" but I do not want to fiddle with modes. Switching the mode would probably have some other side-effect (based on the users priority preferences).

Any ideas how to mute notification sound and vibration on Android 5.0+?

Answer Source

Since nobody came up with a solution, I'm going to answer my own question.

It seems that there is really no way to achieve what I wanted, at least with the latest Android versions. So I ended up doing the following ugly workaround:

I'm now muting the whole phone (incoming phone calls and notifications) via RINGER_MODE_SILENT but also listen for incoming phone calls via a BroadcastReceiver. As soon as an incoming call is detected, the RingerMode gets reverted to its previous state. This effectively leads to the functionality I wanted to achieve.

I'm, however, extremely unsatisfied with this workaround.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download