How to set speaker volume to lowest?

1k views Asked by At

I need to set speakerphone volume to the lowest possible through Audio Manager. I need the lowest volume index.

AudioManager audioManager = 
    (AudioManager)getSystemService(Context.AUDIO_SERVICE);

audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                             [int value] = ?,
                             0);

I did a search on SO, but found nothing usefull.

3

There are 3 answers

0
Deepanshu Gandhi On BEST ANSWER
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
        AudioManager.ADJUST_LOWER, 
        AudioManager.FLAG_SHOW_UI);
0
SAM On

you can do it by the below code

audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                    AudioManager.ADJUST_LOWER, 0);
0
Rajan Bhavsar On
private AudioManager audio;

Inside onCreate:

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

Override onKeyDown:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
    audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
            AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
    return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
    audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
            AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
    return true;
default:
    return false;
}
}