From cf9d94a72b3974ae356dece85388456b1990c306 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 12 Oct 2022 22:36:17 +0100 Subject: [PATCH] Fix Android 13 being unable to launch attachment picker - Android 13 requires the read_media_images permission instead of read external --- .../dapk/st/messenger/gallery/ImageGalleryActivity.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/ImageGalleryActivity.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/ImageGalleryActivity.kt index 7ccd939..1b4a23e 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/ImageGalleryActivity.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/gallery/ImageGalleryActivity.kt @@ -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.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