PermissionsDispatcher icon indicating copy to clipboard operation
PermissionsDispatcher copied to clipboard

Android 13 storage permission in @NeedsPermission

Open gaurav90jain opened this issue 1 year ago • 5 comments

Need to ask for READ_EXTERNAL_STORAGE) permission for API level lower than 33 and ask for READ_MEDIA_IMAGES permission for API level equal or higher than 33. then we should use like below private val readImagePermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) Manifest.permission.READ_MEDIA_IMAGES else Manifest.permission.READ_EXTERNAL_STORAGE if(ContextCompat.checkSelfPermission(this, readImagePermission) == PackageManager.PERMISSION_GRANTED){ //permission granted } else { //permission not granted }

But post using lib of permission dispatcher we should use as @NeedsPermission({Manifest.permission.READ_MEDIA_IMAGES,Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}) but it is not working.

gaurav90jain avatar Apr 17 '23 11:04 gaurav90jain

any update on this issue, how did you resolve it?

roshanrai06 avatar May 09 '23 06:05 roshanrai06

https://developer.android.com/training/permissions/requesting

jarhot1992 avatar Jun 07 '23 03:06 jarhot1992

How did you resolve the issue?

marvil6 avatar Jul 21 '23 18:07 marvil6

I had to do something ugly to get this to work, you can't have the Api 33 and Api < 33 permission in the same annotation or else it won't work:

fun startAddToQueueApiCheck() {
        if (sdk33OrHigher) {
            startAddToQueue33WithPermissionCheck()
        } else {
            startAddToQueue32WithPermissionCheck()
        }
    }

    @NeedsPermission(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE)
    fun startAddToQueue32() {
        startAddToQueue()
    }

    @NeedsPermission(READ_MEDIA_AUDIO, READ_MEDIA_VIDEO)
    fun startAddToQueue33() {
        startAddToQueue()
    }

    fun startAddToQueue() {
       //actually do the thing here
    }

and then call the startAddToQueueApiCheck() for using it

You have to also separate out the @OnShowRationale and @OnPermissionDenied and @OnNeverAskAgain. For example:

 @OnPermissionDenied(READ_MEDIA_AUDIO, READ_MEDIA_VIDEO)
    fun showDeniedForMedia() {
        ..
    }

    @OnPermissionDenied(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE)
  ..
}

I don't think the library is well equipped to handle this in an elegant manner.

svenoaks avatar Aug 24 '23 16:08 svenoaks

I don't think the library is well equipped to handle this in an elegant manner.

That's what happens when requirements change and affected libraries aren't updated. No new update for over 2.5yrs means this project is effectively dead on the latest Android APIs imo.

jschleppy avatar Nov 10 '23 21:11 jschleppy