0
votes

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?

1
Did you find a solution to this?Vero
@Vero No i never diduser3624874
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
@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
I'm glad it worked, I posted my answer so you can accept it.Vero

1 Answers

1
votes

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);