Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 306
rothschild86 Avatar asked Aug 22 '15 18:08

rothschild86


People also ask

How check multiple permissions granted or not Android?

In case one or more permissions are not granted, ActivityCompat. requestPermissions() will request permissions and the control goes to onRequestPermissionsResult() callback method. You should check the value of shouldShowRequestPermissionRationale() flag in onRequestPermissionsResult() callback method.


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

like image 125
Gergely Kőrössy Avatar answered Nov 30 '22 05:11

Gergely Kőrössy


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

like image 30
Sam Avatar answered Nov 30 '22 05:11

Sam