Dobin
Dobin

Reputation: 239

Android 6.0 Permission Denial: requires permission android.permission.WRITE_SETTINGS

As you can see from my manifest below, I've added the permission,What am I missing?

<uses-permission-sdk-m android:name="android.permission.WRITE_SETTINGS" />

Upvotes: 21

Views: 36688

Answers (7)

Brijali Kmphasis
Brijali Kmphasis

Reputation: 11

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);
            }
        }

Upvotes: 0

JustCodingAround
JustCodingAround

Reputation: 1

This is dependent on the API level and the Android build version

Upvotes: -1

KKumar Technologies
KKumar Technologies

Reputation: 267

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            boolean settingsCanWrite = Settings.System.canWrite(this);

            if(!settingsCanWrite) {
                Toast.makeText(this, "Require Permission to Handle Screen Brightness", Toast.LENGTH_LONG).show();
                Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                startActivity(intent);
            }
        }

Upvotes: 0

Mihir Patel
Mihir Patel

Reputation: 486

   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);
        }
    }

this works like a charm.

Upvotes: 3

japanjot singh
japanjot singh

Reputation: 1042

In API 23 or higher user has to authorize manually for this permission, you can check by calling- 'Settings.System.canWrite' below is the implementation for this:-

           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (Settings.System.canWrite(context)) {
                    // Do stuff here
                }
                else {
                    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
                    intent.setData(Uri.parse("package:" + getActivity().getPackageName()));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }

Upvotes: 59

Feng.G
Feng.G

Reputation: 1

This is a special case: permision level:signature ,

If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen.

The app requests the user's approval by sending an intent with action ACTION_MANAGE_WRITE_SETTINGS.

The app can check whether it has this authorization by calling Settings.System.canWrite().

Upvotes: 0

Sam
Sam

Reputation: 42377

It turns out you need to use a different mechanism to be granted WRITE_SETTINGS in Android 6. requestPermissions doesn't work, but CommonsGuy has provided a workaround here: https://stackoverflow.com/a/32083622/238753

Upvotes: 4

Related Questions