版權聲明:本文爲延成原創文章,轉載請標明出處
/**
* 獲取當前手機系統亮度
*
* @return
*/
private float getSystemBrightness() {
float systemBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
try {
systemBrightness = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS) / 255f;
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
return systemBrightness;
}
/**
* 設置屏幕亮度
*
* @return
*/
private void setScreenLight() {
Activity activity = (Activity) mContext;
Window window = activity.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
if (params.screenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE) {
params.screenBrightness = getSystemBrightness();
window.setAttributes(params);
}
}