你的位置:首页 > 操作系统

[操作系统]android 6.0获取 WRITE_SETTINGS 权限


android 6.0上只写在AndroidManifest中是不行的,还必须手动打开才行

private void setBrightnessMode(Context context, int mode) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Settings.System.canWrite(context)) { Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, mode); } else { 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(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, mode); } } catch (Exception e) { e.printStackTrace(); } }