简体   繁体   中英

Permissions are granted by default

I'm not sure i fully understand this. So, for the <= 21 API version we can just use AndroidManifest.xml to request permissions, but Lollipop and higher APIs we have Requesting permission on runtime feature. So i'm using it with this simpe code:

if (Build.VERSION.SDK_INT >= 23) {
    mPermissionsToBeAsked.clear();
    for (String permission : AudioRecordingThread.PERMISSIONS_NEEDED) {
        if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            mPermissionsToBeAsked.add(permission);
        }
    } ....

Then, if that list is not empty i'm requesting them :

if (mPermissionsToBeAsked.size() > 0) {
   requestPermissions(mPermissionsToBeAsked.toArray(new String[0]), AUDIO_PERMISSIONS_REQUEST_CODE);
}

But, for some reason, on devices, for example, like Samsung Galaxy S7 with Android 6.0.1, all the permissions grandted by default when app is installed . So i want to know why, BUT, it's there is an even bigger concerne, when i go to my application in Application Manager and manually removing Microphone permision, in the app checkSelfPermission(permission) is still returning GRANTED . So the questions:

  1. Why on devices with API level Lollipop and higher all permissions are still granted by default and above code won't add anything into mPersmissionToBeAsked ?
  2. Why if i manually removing permission with title MICROPHONE in Application manager checkSelfPermission(android.permission.RECORD_AUDIO) still returns GRANTED ?

Just Cross verify in your app gradle file the targetsdk version is greater than 22.

 defaultConfig {
        // -----
        targetSdkVersion 23
       //----
    }

If it is less than 23 than permission will automatically been granted to your app.

First of all it's Android M and above that handles permission granting. And that means you should have

targetSdkVersion 23 

or above. Otherwise the system considers that the developper did not target this version, meaning that the developper does not check for permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM