Merge pull request #201 from ouchadam/bug/android-13-attachments

Fix Android 13 being unable to launch attachment picker
This commit is contained in:
Adam Brown 2022-10-12 23:03:43 +01:00 committed by GitHub
commit aedc56ef59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import androidx.activity.result.contract.ActivityResultContract
@ -32,7 +33,7 @@ class ImageGalleryActivity : DapkActivity() {
val permissionState = mutableStateOf<Lce<PermissionResult>>(Lce.Loading())
lifecycleScope.launch {
permissionState.value = runCatching { ensurePermission(Manifest.permission.READ_EXTERNAL_STORAGE) }.fold(
permissionState.value = runCatching { ensurePermission(mediaPermission()) }.fold(
onSuccess = { Lce.Content(it) },
onFailure = { Lce.Error(it) }
)
@ -49,6 +50,12 @@ class ImageGalleryActivity : DapkActivity() {
}
}
}
private fun mediaPermission() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Manifest.permission.READ_MEDIA_IMAGES
} else {
Manifest.permission.READ_EXTERNAL_STORAGE
}
}
@Composable