From 4762b80859b942a3ede6a0037acc9bbea6472359 Mon Sep 17 00:00:00 2001 From: toshanmugaraj Date: Tue, 17 Sep 2024 13:06:18 +0300 Subject: [PATCH] grant uri permission crashing --- .../src/main/java/im/vector/lib/multipicker/Picker.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt b/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt index 3010c149944..f645155bfdd 100644 --- a/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt +++ b/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt @@ -26,6 +26,7 @@ import androidx.activity.result.ActivityResultLauncher import im.vector.lib.core.utils.compat.getParcelableArrayListExtraCompat import im.vector.lib.core.utils.compat.getParcelableExtraCompat import im.vector.lib.core.utils.compat.queryIntentActivitiesCompat +import timber.log.Timber /** * Abstract class to provide all types of Pickers. @@ -115,6 +116,14 @@ abstract class Picker { } } } - return selectedUriList.onEach { context.grantUriPermission(context.applicationContext.packageName, it, Intent.FLAG_GRANT_READ_URI_PERMISSION) } + selectedUriList.forEach { uri -> + try { + context.grantUriPermission(context.applicationContext.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION) + } catch (e: SecurityException) { + // Handle the exception, e.g., log it or notify the user + Timber.w("Picker", "Failed to grant URI permission for $uri: ${e.message}") + } + } + return selectedUriList } }