android 获取和设置屏幕亮度

# 获取屏幕亮度

public static 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;
}
 

# 设置屏幕亮度

public static void setScreenBrightness(Activity activity, int value) {
WindowManager.LayoutParams params = activity.getWindow().getAttributes();
params.screenBrightness = value / 255f;
activity.getWindow().setAttributes(params);
}
 
posted @ 2013-07-08 00:15  AZ_mxl  阅读(540)  评论(0)    收藏  举报