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.
This commit is contained in:
Jorge Martin Espinosa
2025-05-13 17:26:47 +02:00
committed by GitHub
parent b322a4bae5
commit 141099ffb2

View File

@@ -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<ShareIntentHandler.UriToShare> {
private fun getIncomingUris(intent: Intent, fallbackMimeType: String): List<ShareIntentHandler.UriToShare> {
val uriList = mutableListOf<Uri>()
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,
)
}
}