Stack Exchange
com.android.shell was not granted this permission: android.permission.WRITE_SETTINGS
I'm trying to set screen brightness with：
adb shell settings put system screen_brightness 150 

but I got an Error：
java.lang.SecurityException: com.android.shell was not granted  this permission: android.permission.WRITE_SETTINGS.
    at android.provider.Settings.isCallingPackageAllowedToPerformAppOpsProtectedOperation(Settings.java:13454)
    at android.provider.Settings.checkAndNoteWriteSettingsOperation(Settings.java:13336)
    at com.android.providers.settings.SettingsProvider.mutateSystemSetting(SettingsProvider.java:1690)
    at com.android.providers.settings.SettingsProvider.insertSystemSetting(SettingsProvider.java:1629)
    at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:494)
    at android.content.ContentProvider$Transport.call(ContentProvider.java:483)
    at com.android.providers.settings.SettingsService$MyShellCommand.putForUser(SettingsService.java:387)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:285)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:731)


To use WRITE_SETTINGS, based on the docs:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

Add above line in your manifest and for Android M or above devices use this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (!Settings.System.canWrite(getApplicationContext())) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, 200);

            }
        }

