Android -- 屏幕亮度

获取屏幕亮度

int getScreenBrightness(Activity activity) {
    int value = 0;
    ContentResolver cr = activity.getContentResolver();
    try {
        value = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
    } catch (SettingNotFoundException e) {
        
    }
    return value;
}

设置屏幕亮度

void setScreenBrightness(Activity activity, float value) {
    WindowManager.LayoutParams params = activity.getWindow().getAttributes();
    params.screenBrightness = value;
    activity.getWindow().setAttributes(params);
}

screenBrightness 的取值范围在[0,1]之间。

我是天王盖地虎的分割线

posted @ 2015-01-23 09:30  我爱物联网  阅读(941)  评论(1编辑  收藏  举报
AmazingCounters.com