如何在android中以编程方式在设置中获取自动亮度的状态为ON或OFF

时间:2011-07-20 06:15:17

标签: android

我创建了toglle按钮,用于自动亮度设置已更改。我想知道自动亮度是ON还是OFF状态,如果它处于打开状态,togglebutton将关闭,如果它打开切换按钮将关闭,如何在这里做

请帮帮我

3 个答案:

答案 0 :(得分:1)

Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);

使用SCREEN_BRIGHTNESS_MODE模式 http://developer.android.com/reference/android/provider/Settings.System.html

答案 1 :(得分:1)

int brightnessmode;

getBrightMode();

if(brightnessmode==1){
//below code will off the auto mode

                android.provider.Settings.System.putInt(contentresolver, Settings.System.SCREEN_BRIGHTNESS_MODE,
                        Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

//Here perform any action you want
}

if(brightnessmode==0){
//below code will on the auto mode

                android.provider.Settings.System.putInt(contentresolver, Settings.System.SCREEN_BRIGHTNESS_MODE,
                        Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
//Here perform any action you want
}

//This method will give brightness mode
//if brigthnessmode=0 means Auto mode is currently off
//if brightnessmode=1 means Auto mode is currently on
protected void getBrightMode() {
// TODO Auto-generated method stub
    try {
        brightnessmode = System.getInt(contentresolver, System.SCREEN_BRIGHTNESS_MODE);
    } catch (Exception e) {
        Log.d("tag", e.toString());
    }
}

答案 2 :(得分:0)

您应该可以从Settings.System阅读此内容,查找SCREEN_BRIGHTNESS_MODE