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

前提是你 提交于 2019-12-01 12:26:30

问题


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+?


回答1:


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.



来源:https://stackoverflow.com/questions/31235609/how-to-mute-sound-and-vibration-for-all-notifications-in-android-5-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!