From 141099ffb244e214d8fdf82c0fd029529d64b9cc Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Tue, 13 May 2025 17:26:47 +0200 Subject: [PATCH] Fix generic mime type being uploaded when several files are externally shared with the app. (#4715) i.e. `image/*` when sharing a png and jpg file. --- .../android/features/share/impl/ShareIntentHandler.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/features/share/impl/src/main/kotlin/io/element/android/features/share/impl/ShareIntentHandler.kt b/features/share/impl/src/main/kotlin/io/element/android/features/share/impl/ShareIntentHandler.kt index 479ca773b5..b2b1dd36e6 100644 --- a/features/share/impl/src/main/kotlin/io/element/android/features/share/impl/ShareIntentHandler.kt +++ b/features/share/impl/src/main/kotlin/io/element/android/features/share/impl/ShareIntentHandler.kt @@ -89,7 +89,7 @@ class DefaultShareIntentHandler @Inject constructor( * Use this function to retrieve files which are shared from another application or internally * by using android.intent.action.SEND or android.intent.action.SEND_MULTIPLE actions. */ - private fun getIncomingUris(intent: Intent, type: String): List { + private fun getIncomingUris(intent: Intent, fallbackMimeType: String): List { val uriList = mutableListOf() if (intent.action == Intent.ACTION_SEND) { IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java) @@ -115,9 +115,12 @@ class DefaultShareIntentHandler @Inject constructor( } } return uriList.map { uri -> + // The value in fallbackMimeType can be wrong, especially if several uris were received + // in the same intent (i.e. 'image/*'). We need to check the mime type of each uri. + val mimeType = context.contentResolver.getType(uri) ?: fallbackMimeType ShareIntentHandler.UriToShare( uri = uri, - mimeType = type + mimeType = mimeType, ) } }