Prashant Patel
Prashant Patel

Reputation: 1097

How to programmatically Mute/Silent devices running Lollipop?

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.

Upvotes: 5

Views: 9234

Answers (2)

Mohmad Iqbal Lone
Mohmad Iqbal Lone

Reputation: 459

Replace RINGER_MODE_SILENT with RINGER_MODE_VIBRATE

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

Upvotes: 1

Tushar Saha
Tushar Saha

Reputation: 2106

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.

Upvotes: 2

Related Questions