5

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.

Prashant Patel
  • 1,087
  • 11
  • 18
  • I read [this](https://www.androidpit.com/android-5-0-lollipop-silent-mode) and is that the problem? Lollipop has no 0 volume option? – Chintan Rathod Sep 14 '15 at 10:15

2 Answers2

2

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.

Tushar Saha
  • 1,978
  • 24
  • 29
1

Replace RINGER_MODE_SILENT with RINGER_MODE_VIBRATE

AudioManager audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audiomanage.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);