Catalin Morosan
Catalin Morosan

Reputation: 7937

Trigger system volume bar

Is it possible by pressing a button in my Activity to make the volume bar appear? The volume bar is the view that appears when you press one of the hardware volume buttons.

Is there a API function to do this or do I have to recreate that view by hand?

Upvotes: 1

Views: 3254

Answers (3)

Halil Ozel
Halil Ozel

Reputation: 3322

I use this code to turn sound on/off:

    val audio = getSystemService(getApplication(), Context.AUDIO_SERVICE) as AudioManager
    audio.adjustStreamVolume(
        AudioManager.STREAM_MUSIC,
        AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI
    )
}

It's worked.

Upvotes: 0

vishalknishad
vishalknishad

Reputation: 744

Working code

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                    AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);

Upvotes: 3

yano
yano

Reputation: 4473

if you call setStreamVolume, pass the flag FLAG_SHOW_UI See http://developer.android.com/reference/android/media/AudioManager.html#FLAG_SHOW_UI

Upvotes: 7

Related Questions