Android 设置系统亮度
最近在做定制Android系统,Setting的源码看的我头疼,记录一下小小的知识点:
首先需要在Manifest申请权限
<uses-permission android:name="android.permission.SET_WALLPAPER" />
亮度的值一般在0~255
获取当前亮度:
private int getScreenBrightness(Context context) {
ContentResolver contentResolver = context.getContentResolver();
int defVal = 125;
return Settings.System.getInt(contentResolver,
Settings.System.SCREEN_BRIGHTNESS, defVal);
}
获得亮度最大值:
Settings.System.getInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS)
设置亮度:
private void ModifySettingsScreenBrightness(Context context,
int birghtessValue) {
setScreenManualMode(context);
ContentResolver contentResolver = context.getContentResolver();
Settings.System.putInt(contentResolver,
Settings.System.SCREEN_BRIGHTNESS, birghtessValue);
}
|