以编程方式更改自适应亮度级别 [英] Change adaptive brightness level programmatically
问题描述
如何在Android Lollipop上以编程方式更改自适应亮度级别?
我知道如何更改手册brightness level
,以及如何打开或关闭adaptive brightness
.这样做是这样的:
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, newLevel);
但是,在启用adaptive brightness
的情况下,操作系统将其与另一个brightness level
组合,该brightness level
与手动操作不同.
有没有办法做到这一点?
目标/最小/最大SDK为21.
不知道为什么,但是Android API中有一个隐藏的常量SCREEN_AUTO_BRIGHTNESS_ADJ
来调整自适应亮度.但是您可以像我一样通过"screen_auto_brightness_adj"
字符串值.
自适应亮度调节以浮点值的形式存储在[-1; 1]范围内.如果您使用[0; 255]范围内的亮度值,则可以将其转换为合适的值,如下所示.
float value = (((float)brightness*2)/255) - 1.0f;
Settings.System.putFloat(contentResolver, "screen_auto_brightness_adj", value);
How can I change the adaptive brightness level programmatically, on Android Lollipop?
I know how to change the manual brightness level
, and to toggle on or off the adaptive brightness
. It is done like that:
Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, newLevel);
However, with adaptive brightness
is enabled, the OS combines it with another brightness level
which is different than the manual one.
Is there a way to do this?
Target/min/max SDK is 21.
Don't know why but there is a hidden constant SCREEN_AUTO_BRIGHTNESS_ADJ
in Android API to adjust adaptive brightness. But you can pass "screen_auto_brightness_adj"
string value instead like I did.
Adaptive brightness adjustment is stored as float value in range [-1;1]. If you use brightness value in range [0;255], you can convert it to proper value as shown below.
float value = (((float)brightness*2)/255) - 1.0f;
Settings.System.putFloat(contentResolver, "screen_auto_brightness_adj", value);
这篇关于以编程方式更改自适应亮度级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!