Home » Android » Android 6 Marshmallow: requests for some specific permissions are instantly denied with no ui shown

Android 6 Marshmallow: requests for some specific permissions are instantly denied with no ui shown

Posted by: admin June 16, 2020 Leave a comment

Questions:

Using official AVD rev. 3

Calling this:

ActivityCompat.requestPermissions(activity, new String[]{"android.permission.USE_CREDENTIALS"}, REQUEST_PERMISSION_CREDENTIALS);

Fires immediately:

onRequestPermissionsResult (int requestCode, String[] permissions, int[] grantResults)

And resulting code is PackageManager.PERMISSION_DENIED

Anyone has a fix?

UPDATE:
Known to be affected:

Manifest.permission.CHANGE_NETWORK_STATE
Manifest.permission.WRITE_SETTINGS (solved, see Sam's answer)
android.permission.USE_CREDENTIALS (solved, read Update 2)
READ_SMS

UPDATE 2:
See excellent accepted answer. Essentially, USE_CREDENTIALS is a safe permission now. Beats me why sdk not simply return PERMISSION_GRANTED for it…

How to&Answers:

Refer to these pages: permissions by protection level and protection level definitions.

Manifest.permission.CHANGE_NETWORK_STATE

Manifest.permission.WRITE_SETTINGS

These fall under the protection level “signature|appop|pre23|preinstalled” which means that only same-signature apps (system signed basically), app operators, apps that target below API level 23 and presintalled apps can have these.

android.permission.USE_CREDENTIALS

This is only needed on API level 22 and below. See this.

Also you should check out the Behavior Changes.

Answer:

Regarding WRITE_SETTINGS, CommonsGuy has provided a workaround here: https://stackoverflow.com/a/32083622/238753

Answer:

Seems like you’ve got it sorted. I had this same symptom with a more foolish cause.

I had my uses-permission nodes INSIDE my application node in my manifest. This seemed to work on 22 or less but moving to 23 seemed to not recognize it and thus auto deny the permission.

Hopefully this helps someone else stuck on this.

Answer:

first check for Marshmellow version then paste this in your code after changing the activity name

if (!android.provider.Settings.System.canWrite(RingdroidEditActivity.this)) {
                    Intent intentt = new     Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
                intentt.setData(Uri.parse("package:" + RingdroidEditActivity.this.getPackageName()));
                intentt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intentt);
            }

This will take you to the permission page of the app and ask the user to give permission

WRITE_SETTINGS after marshmellow has been changed
this will work
to see the example check this application