How I can make my phone mute in lollipop devices programmatically? For pre-lollipop devices, it can be done pretty well using AudioManager
class but In android 5.0 and above, the device can be kept on Vibrate mode but I am not able to mute it. Can anyone help me out that how can we programmatically change phone's volume modes between NONE, PRIORITY and ALL?
Thanks.
use this code:
final AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
and give this permission in manifest
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
i tried it on android 5.0.1 in an onclick event. it sets phone in priority then triggering the onclick again will place the phone in no interruption.
Replace RINGER_MODE_SILENT with RINGER_MODE_VIBRATE
AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audiomanage.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With