9

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...

rothschild86
  • 1,433
  • 16
  • 22

4 Answers4

6

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.

Community
  • 1
  • 1
Gergely Kőrössy
  • 5,620
  • 3
  • 28
  • 44
  • 1
    It seems that WRITE_SETTINGS can be granted using the specific menu under "Apps" on android M. If the app target < 23 the permission is granted by default, if the app target is >= 23 the permission is not granted by default. The problem is that with these kind of permissions, the checkSelfPermissions & co. seems not work. – greywolf82 Aug 23 '15 at 07:46
  • I think it's there to allow the user to revoke this permission from pre-23 apps. Since you cannot access it through the API, it doesn't matter whether you can grant it in the settings menu. – Gergely Kőrössy Aug 23 '15 at 12:59
  • @rothschild86 So how did you solve it ? I keep getting permission denied without a dialog. – Danpe Oct 16 '15 at 16:34
  • @Danpe which permission are you dealing with? – rothschild86 Oct 16 '15 at 20:23
  • @Danpe this seems to be a known issue: https://code.google.com/p/android/issues/detail?id=189841 and it doesn't seem to be fixed as of yet. I'm using `Location` permissions and no dialog shows up even though it's stated that this is "Dangerous permission" (see: http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous). – Darwind Nov 05 '15 at 23:23
1

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

Community
  • 1
  • 1
Sam
  • 40,644
  • 36
  • 176
  • 219
1

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.

Joe
  • 11
  • 1
0

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

laalto
  • 150,114
  • 66
  • 286
  • 303