2

When I execute this code:

mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT );

the icon in my menubar on top is set to the vibrate icon and the vibrate setting is set to vibrate and not to silent.

What I expect from 'silent' is no-vibrate, no-sound.

It's on my phone on Android 4.4.4

Michel
  • 23,085
  • 46
  • 152
  • 242
  • What device are you testing on? At least in a Nexus 4 with 4.4.4 this code DOES set the proper "silent" mode (including icon). – matiash Dec 04 '14 at 14:27
  • you mean silent as in 'no sound' or realy as in 'no sound AND no vibrate' ? – Michel Dec 05 '14 at 08:40
  • Silent as in "no sound and no vibrate" (i.e. pressing "volume up" afterwards switches to vibrate mode). With Android 5.0 however it turns on Priority Mode instead. What phone are you testing on? – matiash Dec 05 '14 at 14:03
  • 1
    I'm running on a motorola moto G. If you are so confident it should work, I'll look again. – Michel Dec 08 '14 at 10:17
  • 1
    Well, it _does_ look like the correct way of doing it, and it works in the 4.4.4 device I have available. I can't affirm anything else apart from that, unfortunately. Good luck! – matiash Dec 10 '14 at 00:57
  • only working in nexux and samsung devices. In Moto not working. – Abhi Nov 23 '16 at 09:19

3 Answers3

1

Try this :

AudioManager audio = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audio.setRingerMode(0);

Android Manifest file:

<application>
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
</application>
Han
  • 449
  • 5
  • 18
Vivek Shah
  • 380
  • 2
  • 8
1
 mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
    mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);

For more detail here

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
0

Try use this for silent mode:

getSystemService( Context.AUDIO_SERVICE).setRingerMode( AudioManager.RINGER_MODE_SILENT);

or normal mode:

getSystemService( Context.AUDIO_SERVICE).setRingerMode( AudioManager.RINGER_MODE_NORMAL);

Also permissions and uses-sdk (insode 'manifest' not 'application'):

<manifest ...>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
</manifest>
Tapa Save
  • 4,769
  • 5
  • 32
  • 54
  • 3
    No app outside of the system/firmware can get the `android.permission.WRITE_SECURE_SETTINGS` permission. You can ask for it but what you get is a different story [see here.](http://stackoverflow.com/a/5034276/1986583) – Hartmut Pfitzinger Dec 11 '14 at 06:14