原地址:http://blog.csdn.net/hnkwei1213/article/details/54947339java
app用到了调整系统亮度的功能,在清单文件中添加了android.permission.WRITE_SETTINGS权限,但运行在6.0系统一直报错:java.lang.SecurityException: so.wih.android.jjewatch was not granted this permission: android.permission.WRITE_SETTINGS.android
解决方法以下:app
//设置系统亮度
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.System.canWrite(context)) {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
//有了权限,具体的动做
Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, progress);
data2 = intToString(progress, 255);
tvSunlightValue.setText(data2 + "%");
}
}