简体   繁体   English

有效改变屏幕亮度

[英]Changing screen brightness efficiently

I need to change the screen brightness programmatically. 我需要以编程方式更改屏幕亮度。 I read multiple solutions like this Can't apply system screen brightness programmatically in Android . 我读过这样的多个解决方案无法在Android中以编程方式应用系统屏幕亮度

My problem is that those solutions implies changing the activity to be effective (having something like a dummy activity finishing immediately) and I would like to avoid the overhead of an activity switch. 我的问题是,这些解决方案意味着将活动更改为有效(有一个虚拟活动立即完成),我想避免活动开关的开销。

Is there any other solution... maybe using native code so that the screen brightness will change immediately ? 有没有其他解决方案...可能使用本机代码,以便屏幕亮度会立即改变?

The following affects immediately the single activity, no need to restart it. 以下操作立即影响单个活动,无需重新启动它。 The activity also remembers the screenBrightness attribute over pause/resume. 该活动还会记住暂停/恢复时的screenBrightness属性。

WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 1; // 0f - no backlight ... 1f - full backlight
getWindow().setAttributes(lp);

But it has no effect if you have automatic backlight level enabled in the system settings. 但如果在系统设置中启用了自动背光级别,则无效。 This solution should help to turn off automatic backlight. 此解决方案应该有助于关闭自动背光。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM