Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this simple code to set the SCREEN_BRIGHTNESS at System level in Android (not just for my app):

Java
android.provider.Settings.System.putInt(MyContext.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); //Set it to manual mode
android.provider.Settings.System.putInt(MyContext.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, MyValue); //Set a specific value


According to docs values can be from 0 to 255.

But I get strange results as displayed in the Android settings or on the notification panel where you can see the screen brightness slider.

If I set MyValue to 0, it works correctly. The screen brightness is set to the minimum. Good.

Also, if I set MyValue to 255, it works correctly. The screen brightness is set to the maximum. Good.

Problems start if I set other values, like a 50% (which is 255/2=128). In this case the screen brightness is not set to 50%, it is something like 90%.

If I set it to 25% (which is 255/4=56), the screen brightness is not set to 25%, it is something like 70%.

If I set it to 10% (which is 255/10=26), the screen brightness is not set to 10%, it is something like 40%.

I think I am missing something here. Any help?

What I have tried:

I have tried in emulator and real devices
Posted
Comments
David Crow 2-Dec-21 10:10am    
Something I would try is to set the brightness at 50% using the slider. Then use your code to read the value. Does it read as 128?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900