Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen brightness value in Android

Tags:

android

How do you get the current screen brightness of your activity?

Following method works fine for setting the brightness to max by calling setBrightness(100):

private void setBrightness(int brightness) {
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = brightness/100.0f;
    getWindow().setAttributes(layoutParams);
}

Im trying to achieve the following:

  1. Start the activity and save the current brightness value
  2. Set brightness to max
  3. Reset brightness to the initial value on certain events

Many thanks!

like image 464
lukuluku Avatar asked Oct 09 '11 16:10

lukuluku


People also ask

What is ideal brightness for Android?

Anything around 600 nits is good enough, but there are smartphones that push the brightness to over 1000 nits. Too low brightness or going for too high brightness is very dangerous for eyes.

What is brightness in Mobile?

Adaptive brightness gives your phone the ability to adjust the screen brightness automatically depending on the amount of light around you. The setting is typically on by default, but it's easy to turn off if you want to. Swipe down from the top of the screen to reveal the Notification Shade.

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.

What is automatic brightness on Android?

Adaptive Brightness helps your phone to learn your preferred screen brightness in different lighting. Your phone's screen brightness will be automatically set for you.


1 Answers

Try

int curBrightnessValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);

and then

   WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.screenBrightness = curBrightnessValue/100.0f;
    getWindow().setAttributes(layoutParams);
like image 113
Michele Avatar answered Sep 28 '22 00:09

Michele