Android Question RuntimePermissions confusion

JohnC

Expert
Licensed User
Longtime User
I am finally working with runtime permissions for the first time and I am confused about something...

From what I understand, a statement like below is needed in the manifest when the app is running on a version of android that does not support runtime permissions.

B4X:
AddManifestText(<uses-permission
    android:name="android.permission.READ_CONTACTS"
    android:maxSdkVersion="18" />
)

And it is my understanding that the "18" parameter means "This permission statement is only applicable for devices running android API level 18 or less".

And from what I also understand, Android 6.0 (API 23) is when runtime permissions were implemented.

So, what is confusing to me is what happens when the app is run on a device with an API level of 19 (android 4.4) to 22 (android 5.1)?

Meaning, if the manifest declaration is only valid for device API's up to level 18, then what happens when the app runs on a lollipop device (android 5.0, API 21) and it needs to access the contacts, but android 5.0 does not support runtime permissions?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
From what I understand, a statement like below is needed in the manifest when the app is running on a version of android that does not support runtime permissions.
You have misunderstood. The maxSdkVersion is only relevant to one specific permission, the storage permission. Watch the video tutorial.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I did watch the video and it talked about the storage example, and since it did not mention that maxSdkVersion was ONLY for the "storage" permission, that lead me to believe the maxSdkVersion should be used in the manifest for the other dangerous permissions so that the app can run on android versions before version 6.0.

So, then if my app needs to access the contacts, then I should place the following statement in the manifest?

B4X:
AddPermission("android.permission.READ_CONTACTS")

And just so I understand this correctly, if I do include the above line in my app's manifest, would the below things then happen?

1) When installing the app on a device running android 4-5.1, it will immediately pop-up a dialog saying that the app requires access to the contacts, and
2) If the app is installed on a device running android 6+, it will NOT immediately pop-up a dialog when installing an app, but it will eventually pop-up a permission prompt when my code runs the first "rp.CheckAndRequest(rp.permission.READ_CONTACTS)"?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
So, then if my app needs to access the contacts, then I should place the following statement in the manifest?
No. It will be added automatically like it always did.

1) It will show the list of permissions during installation.
2) True.

In all cases you need to call rp.CheckAndRequest. Don't try to call it based on the device version.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Ah, thank you - that clears up a lot.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…