Search code examples
androidbrightnessindicatorscreen-brightness

Show brightness indicator bar when changed programmatically android


So i have a working code to change the brightness of the screen like in the answer her -

Change the System Brightness Programmatically

I just cant find anywhere how can i show the device's brightness indicator bar changing while the user changes it from the app.

For changing the volume for instance there is a flag that tells it to show the UI (FLAG_SHOW_UI) -

mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, newStreamVolume, AudioManager.FLAG_SHOW_UI);

I am trying to achieve the same effect but on the brightness param.

Any ideas?


Solution

  • Unlike the volume, there is no physical button to change the brightness and thus it becomes pointless to have a popup indicating the brightness change. Note that the volume can be changed on the screen controls and with buttons controls which show the popup but the brightness can only change on the screen controls.

    You can implement your code by using a SeekBar to display the brightness level. Set the current level of brightness by getting the current brightness

    Settings.System.getInt(getContext().getContentResolver(), 
             Settings.System.SCREEN_BRIGHTNESS);