我想以编程方式将屏幕亮度更改为0,以便使用:
public static void reduceBrightness(Context context) {
if (Build.VERSION.SDK_INT < 23 || Settings.System.canWrite(context)) {
try {
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
}
}
已授予权限。
但是,当我继续更改某些设置(例如wifi,蓝牙)时,亮度将变为非零值(即降低亮度之前的值)
请帮助我更正代码。
答案 0 :(得分:0)
使用此代码将亮度传递的int值从 0更改为255。
public void setScreenBrightness(int brightnessValue){
// Make sure brightness value between 0 to 255
if(brightnessValue >= 0 && brightnessValue <= 255){
Settings.System.putInt(
mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS,
brightnessValue
);
}
}
也要授予以下权限
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>