使用WindowManager调整屏幕亮度会在不活动后停止工作

时间:2011-05-23 23:50:06

标签: android

我正在使用此代码通过调暗来更改活动的亮度。

WindowManager.LayoutParams layoutParameters = getWindow().getAttributes();
layoutParameters.screenBrightness = 0.0075f;
getWindow().setAttributes(layoutParameters);

我也在调整android.provider.Settings.System的亮度。

我的问题是,在不活动约8秒后,屏幕亮度恢复正常(即再次亮起)。有谁知道为什么会发生这种情况以及如何改变这种设置呢?

谢谢!

2 个答案:

答案 0 :(得分:1)

我不知道它是否会覆盖你的layoutParameters,但也许会尝试使用完整的wakeLock来防止屏幕变暗。

答案 1 :(得分:0)

您应该将Settings.System.SCREEN_BRIGHTNESS_MODE的值从Automatic更改为manual,然后更改int值Settings.System.SCREEN_BRIGHTNESS。只添加以下代码行:

Settings.System.putInt(getActivity().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(getActivity().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness);//for persistent change
相关问题