How to enable/disable auto brightness mode from API

我怕爱的太早我们不能终老 提交于 2019-12-24 10:38:44

问题


I want to control the system settings "auto brightness", setting it ON or OFF. I'm able to control the brightness level but only if AUTO is OFF. From what I read until now there is a SCREEN_BRIGHTNESS_MODE in Settings.System but only for API level 8 or higher and also not recommended to mess wit it. But currently my phone has Android 2.1 (API 7) and there are widgets that can control this setting (enable/disable auto brightness and set the level). How is this done?


回答1:


I solved my problem using:

private static final String SCREEN_BRIGHTNESS_MODE = "screen_brightness_mode";
private static final int SCREEN_BRIGHTNESS_MODE_MANUAL = 0;
private static final int SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1; 

Settings.System.putInt(resolver, SCREEN_BRIGHTNESS_MODE, mode); 
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, lev);

This works in API versions 7 and 8, not sure about earlier versions.




回答2:


I guess this should work for you:

Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE, mode); 
Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, lev);

And remember to add permission:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />


来源:https://stackoverflow.com/questions/3957749/how-to-enable-disable-auto-brightness-mode-from-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!