PermissionsDispatcher
PermissionsDispatcher copied to clipboard
Android 13 storage permission in @NeedsPermission
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.
any update on this issue, how did you resolve it?
https://developer.android.com/training/permissions/requesting
How did you resolve the issue?
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.
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.