Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 13 storage permission in @NeedsPermission #781

Open
gaurav90jain opened this issue Apr 17, 2023 · 5 comments
Open

Android 13 storage permission in @NeedsPermission #781

gaurav90jain opened this issue Apr 17, 2023 · 5 comments

Comments

@gaurav90jain
Copy link

gaurav90jain commented Apr 17, 2023

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.

@roshanrai06
Copy link

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

@jarhot1992
Copy link

@marvil6
Copy link

marvil6 commented Jul 21, 2023

How did you resolve the issue?

@svenoaks
Copy link

svenoaks commented Aug 24, 2023

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.

@jschleppy
Copy link

jschleppy commented Nov 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants