(转)安卓6.0系统权限申请android.permission.WRITE_SETTINGS

原地址:http://blog.csdn.net/hnkwei1213/article/details/54947339


app用到了调整系统亮度的功能,在清单文件中添加了android.permission.WRITE_SETTINGS权限,但运行在6.0系统一直报错:java.lang.SecurityException: so.wih.android.jjewatch was not granted this permission: android.permission.WRITE_SETTINGS.

解决方法如下:

//设置系统亮度
                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 + "%");
                    }
                }

猜你喜欢

转载自blog.csdn.net/duyiqun/article/details/79448225