How to get current screen's brightness in Android code dynamiclly?
To get the brightness of a screen use the getint() method that returns the current brightness of a system. You will the brightness to the setProgress() method as an argument. Now set the seekbar on setOnSeekBarChangeListener() to change the brightness of a screen.
That may cause various brightness-related glitches. To disable Adaptive Brightness on a Samsung device, go to Settings → Display. Then toggle off Adaptive Brightness. If you want to disable automatic brightness adjustment on Android phones, go to Settings → Display and brightness and toggle off the Automatic option.
On an unlocked device, swipe your finger down from the top of the screen twice. Press and hold your finger on the brightness slider (shown below) and drag left or right to adjust the brightness.
Hi to get the current brightness level of the android system you can use this code:
try {
float curBrightnessValue=android.provider.Settings.System.getInt(
getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This was asked a while ago but just to expand on fiction's answer:
settings.screenBrightness will return -1 if it has not been previously overwritten in code. This is correct behaviour as setting screenBrightness to -1 will set the brightness to the current system brightness level.
This system brightness can be changed by the user at any time, so there is probably not much use in storing the actual value, if you are just trying to return the brightness to its original value, as the actual value might be "out of date".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With