Android 设置系统亮度
作者:互联网
Android 设置系统亮度
最近在做定制Android系统,Setting的源码看的我头疼,记录一下小小的知识点:
首先需要在Manifest申请权限
<uses-permission android:name="android.permission.SET_WALLPAPER" />
亮度的值一般在0~255
获取当前亮度:
/**
* 获取系统默认屏幕亮度值 屏幕亮度值范围(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)
设置亮度:
/**
* 修改Setting 中屏幕亮度值
*
* **/
private void ModifySettingsScreenBrightness(Context context,
int birghtessValue) {
// 首先需要设置为手动调节屏幕亮度模式
setScreenManualMode(context);
ContentResolver contentResolver = context.getContentResolver();
Settings.System.putInt(contentResolver,
Settings.System.SCREEN_BRIGHTNESS, birghtessValue);
}
标签:设置,Settings,System,亮度,contentResolver,context,Android 来源: https://blog.csdn.net/weixin_40303382/article/details/120203459