1

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?

Catalin Morosan
  • 7,897
  • 11
  • 53
  • 73

3 Answers3

6

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

yano
  • 4,095
  • 3
  • 35
  • 68
3

Working code

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                    AudioManager.ADJUST_SAME, AudioManager.FLAG_SHOW_UI);
vishalknishad
  • 690
  • 7
  • 12
0

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.

Halil Ozel
  • 2,482
  • 3
  • 17
  • 32