Skip to content

Commit 4f39e09

Browse files
authored
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.
1 parent f6cbca4 commit 4f39e09

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

features/share/impl/src/main/kotlin/io/element/android/features/share/impl/ShareIntentHandler.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class DefaultShareIntentHandler @Inject constructor(
8989
* Use this function to retrieve files which are shared from another application or internally
9090
* by using android.intent.action.SEND or android.intent.action.SEND_MULTIPLE actions.
9191
*/
92-
private fun getIncomingUris(intent: Intent, type: String): List<ShareIntentHandler.UriToShare> {
92+
private fun getIncomingUris(intent: Intent, fallbackMimeType: String): List<ShareIntentHandler.UriToShare> {
9393
val uriList = mutableListOf<Uri>()
9494
if (intent.action == Intent.ACTION_SEND) {
9595
IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)
@@ -115,9 +115,12 @@ class DefaultShareIntentHandler @Inject constructor(
115115
}
116116
}
117117
return uriList.map { uri ->
118+
// The value in fallbackMimeType can be wrong, especially if several uris were received
119+
// in the same intent (i.e. 'image/*'). We need to check the mime type of each uri.
120+
val mimeType = context.contentResolver.getType(uri) ?: fallbackMimeType
118121
ShareIntentHandler.UriToShare(
119122
uri = uri,
120-
mimeType = type
123+
mimeType = mimeType,
121124
)
122125
}
123126
}

0 commit comments

Comments
 (0)