1

In Android In my app there are 2 buttons to increase and decrease volume. my need is to show UI volume bar(the Volume level dialog in the above of the screen) when I press buttons and hide it after a while.

my problem is:

  • I can ajust volume without show UI
  • I can ajust volume and show UI but then UI is on screen until i tap screen or on button again...

is there a way to hide UI bar after few seconds ?

I tried some solutions :

void volumeUp(){
    final AudioManager myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    myAudioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
}

This show UI bar but it doesn't desapear until i tap screen

   void volumeUp(){
    final AudioManager myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    myAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
            AudioManager.ADJUST_RAISE,
            AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}

same result

  void volumeUp(){
    final AudioManager myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    myAudioManager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
}

this doesn't show UI

I didn't find other solution....

1 Answers1

-1

Add below code in your volumeUp(); method,

final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            AudioManager.setVisivibility(View.GONE);
            }
        }
    }, 1500);