如何才能持久更改 Android 屏幕亮度?
我已经设法使用以下代码更改活动(以及扩展整个应用程序)中的屏幕亮度:
Settings.System.putFloat(this.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, ((float)LocationService.settings.screenBrightness));
WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness = someValue;
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
但是,一旦我关闭应用程序,亮度就会恢复到之前的设置。是否有办法使这些更改在应用程序的生命周期之外持续存在?
谢谢!
I've managed to change screen brightness within an activity (and by extension the entire app) using the following code:
Settings.System.putFloat(this.getContentResolver(),Settings.System.SCREEN_BRIGHTNESS, ((float)LocationService.settings.screenBrightness));
WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness = someValue;
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
However, as soon as I close the app the brightness returns to its previous settings. Is there anyway to make these changes persist outside of the lifecycle of the app?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里也许对你有帮助:
Here maybe help you:
尝试一下
您将需要在 AndroidManifest.xml
http://android-er.blogspot.com/2011/02/change-system-screen-brightness-using.html
Try this
You will need the WRITE_SETTINGS permission set in your AndroidManifest.xml
http://android-er.blogspot.com/2011/02/change-system-screen-brightness-using.html
设置应用程序这样做:
但我怀疑如果没有系统共享用户 ID,您就无法更改系统设置
Settings application does it this way:
but I suspect you cannot change a System Settings without having system shared user id
在 androidMainfest.xml 中提供权限
并提供 0 到 255 之间的整数
Provide the permission in androidMainfest.xml
And provide a integer number between 0 to 255