亮度的值一般在0~255获取当前亮度: /** * 获取系统默认屏幕亮度值 屏幕亮度值范围(0-255) **/ private int getScreenBrightne_android 设置系统亮度">
赞
踩
最近在做定制Android系统,Setting的源码看的我头疼,记录一下小小的知识点:
if (!Settings.System.canWrite(DisplaySettingActivity.this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + DisplaySettingActivity.this.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
DisplaySettingActivity.this.startActivity(intent);
} else {
// 申请权限后做的操作
}
}
/**
* 获取系统默认屏幕亮度值 屏幕亮度值范围(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);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。