开发者

How to enable/disable auto brightness mode from API

开发者 https://www.devze.com 2023-01-20 18:25 出处:网络
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_BRIGHTN

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 onl开发者_JAVA百科y 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?


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.


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" />
0

精彩评论

暂无评论...
验证码 换一张
取 消