I'm having a problem showing the Grant Permissions dialog. If I click on the ImageView, a dialog where the user can choose does not appear as intended, but I get to see the else branch within requestPermissionLauncher directly. I use Android 11. According to the description, the dialog is no longer displayed from Android 11 if a user has denied permission more than once. How do I get it to display this anyway? I can't set READ_EXTERNAL_STORGAE in the settings What am I doing wrong?
CreateShot.tk:
bottomFilter.findViewById<ImageView>(R.id.addImageToShot).setOnClickListener {
when {
ContextCompat.checkSelfPermission(
applicationContext,
Manifest.permission.READ_EXTERNAL_STORAGE
) != PackageManager.PERMISSION_GRANTED -> {
requestPermissionLauncher.launch(
Manifest.permission.READ_EXTERNAL_STORAGE)
}
else -> {
selectImage()
}
}
}
private val requestPermissionLauncher =
registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
selectImage()
} else {
makeToast("Berechtigung nicht erteilt")
}
}
Manifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />