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, ) } }