Request a new runtime permission by updating only compileSDKVersion and without updating targetSDKVersion

109 Views Asked by At

I have seen multiple post around difference between compileSDKVersion and targetSDKVersion but am still confused in case where a new permission was introduced in an api level and we try to request that permission during runtime by only updating the compileSDKVersion and not the targetSDKVersion. For example, in our case we have logic used by one of our dependencies that calls a function that looks like this for requesting runtime permission.

getPermissions(){
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { return new String[] {
                     Manifest.permission.READ_MEDIA_IMAGES,
                     Manifest.permission.READ_MEDIA_VIDEO,
      };
}

Manifest.permission.READ_MEDIA_IMAGES and Manifest.permission.READ_MEDIA_VIDEO were introduced in api 33. So once we use compileSDKVersion 33 (without updating targetSDKVersion) the above code compiles fine. Now when we run the app on android 13 (api 33) what happens in above case. Will the runtime permissions be requested correctly since the docs say we need to target api 33 to actually use these permissions.

Update: Based on my test on android 13, it surely does go inside this block of code and request the two granular media permissions but the runtime dialog box shown actually request permission for images, video, audio & music as well instead of just the two granular permission. So there is definitely some weird behavior I am seeing.

0

There are 0 best solutions below