0

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?

Itay Feldman
  • 846
  • 10
  • 23

2 Answers2

1

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);
Lucem
  • 2,912
  • 3
  • 20
  • 33
0

Add the permission in your manifest:-

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

set the brightness:-

ContentResolver cResolver = this.getApplicationContext().getContentResolver();
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);

You can show a seekbar for the changing brightness:-

//Register OnSeekBarChangeListener, so it can actually change values
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
    public void onStopTrackingTouch(SeekBar seekBar)
    {
        //Set the system brightness using the brightness variable value
        Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);

    }
    public void onStartTrackingTouch(SeekBar seekBar)
    {
        //Nothing handled here
    }
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
    {

    }
});
}
Nainal
  • 1,728
  • 14
  • 27