0

I want to disable ALL sound and vibration from the android device. As per the answers to similar questions, I'm currently using the following code to mute all the audio streams, set the ringer mode to silent, and to fake a voice call scenario:

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
    //DOESNT DISABLE ALARM CLOCK
    amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
    amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
    amanager.setStreamMute(AudioManager.STREAM_RING, true);
    amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    amanager.setStreamMute(AudioManager.STREAM_DTMF, true);
    amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
    amanager.setStreamMute(AudioManager.STREAM_VOICE_CALL, true);
    //disables vibrate and sound of ringer
    amanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    //fakes voice call...changes alarm to single tone+vibrate
    amanager.setMode(AudioManager.MODE_IN_CALL);
    amanager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);

This works for disabling music and incoming calls, but, as noted in the comments, the android's built-in alarm clock app is still able to produce sound and vibration.

Does anyone know how to truly disable ALL sound and vibrations? Or venture a guess as to why the alarm clock app seems to by bypassing the audio streams?

user3624874
  • 25
  • 1
  • 5
  • @Vero No i never did – user3624874 Sep 11 '14 at 01:48
  • Maybe this will help you. After asking you, I found a way to mute the alarm. It was ignoring setStreamMute, but it worked using setStreamVolume to zero for the STREAM_ALARM. It is necessary to restore the alarm volume afterwards. – Vero Sep 12 '14 at 17:44
  • @Vero Thanks! that worked for the sound. Any tips about the vibrations? The only info i could find used deprecated functions. (also, i'm not very experienced on stack overflow; am i supposed to vote for your answer somehow?) – user3624874 Sep 14 '14 at 02:28
  • I'm glad it worked, I posted my answer so you can accept it. – Vero Sep 16 '14 at 17:39

1 Answers1

1

setStreamMute did not work for me to mute the alarm, but using setStreamVolume for STREAM_ALARM setting volume to zero did. It is necessary to restore the alarm volume afterwards.

For example like this:

AudioManager manager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);    
manager.setStreamVolume(AudioManager.STREAM_ALARM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Ali
  • 3,346
  • 4
  • 21
  • 56
Vero
  • 1,742
  • 3
  • 15
  • 29