Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current screen's brightness in Android code dynamiclly?

Tags:

android

How to get current screen's brightness in Android code dynamiclly?

like image 383
yuankai Avatar asked Dec 28 '10 09:12

yuankai


People also ask

How can I get current brightness?

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.

How do I turn on auto brightness on Android?

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.

How do I calibrate the brightness on my Android?

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.


2 Answers

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();
}
like image 161
Midhun VP Avatar answered Dec 03 '22 20:12

Midhun VP


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".

like image 24
Hamiora Avatar answered Dec 03 '22 22:12

Hamiora