Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's ContextCompat.checkSelfPermission() returns incorrect value

I am trying to check for permissions being granted/revoked by user in Android Marshmallow. Unfortunately ContextCompat.checkSelfPermission() (which is a warpper around Context.checkCallingOrSelfPermission) seems to always return PackageManager.PERMISSION_GRANTED (0) if you have included that specific permission in your manifest regardless of the current state of the permission (e.g. if the user has revoked the permission). I also tried someContext.checkCallingOrSelfPermission(), but the result is the same.

Has anyone experienced this? I am using Android Marshmallow on nVidia Shield console (using nVidia's Beta program).

like image 842
Javad Avatar asked Feb 11 '16 14:02

Javad


1 Answers

As it turns out, The targetSdkVersion in the manifest must be 23, mine was 22. If your target SDK is 23 (Android 6), all of the permissions (in your manifest) are disabled by default, whereas if your target SDK is 22 (Android 5.1) and your app is running on Android 6, all of the permissions are enabled by default when the user installs the app, and even if the user revokes the permissions later on, the mentioned API returns incorrect value (which is a bug in my opinion).

like image 105
Javad Avatar answered Sep 23 '22 16:09

Javad