Android的发展:服务改变屏幕亮度亮度、屏幕、Android

2023-09-06 17:24:35 作者:等我足够优秀

现在我做再试一次。

我想改变屏幕亮度。

我已经试过:

WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = 0.5F; // set 50% brightness
getWindow().setAttributes(layoutParams);

和似乎在活动的工作,但是当我在服务,我得到那个 getWindow()编译错误。

and seems to work in activity but when I am in service i get that getWindow() compile error.

推荐答案

一个服务不能改变屏幕亮度的方式。服务没有用户界面,因此它不具有窗口

A service cannot change the screen brightness that way. A service does not have a user interface, so it does not have Window.

您可以尝试通过 SCREEN_BRIGHTNESS 的系统设置。我不知道如果这个工程,因为我还没有尝试过。

You can try to change the brightness system-wide via the SCREEN_BRIGHTNESS system setting. I have no idea if this works, as I have not tried it.

否则,修改您的活动,以改变它们的亮度。

Otherwise, modify your activities to change their brightness.