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:
parent
b322a4bae5
commit
141099ffb2
1 changed files with 5 additions and 2 deletions
|
|
@ -89,7 +89,7 @@ class DefaultShareIntentHandler @Inject constructor(
|
||||||
* Use this function to retrieve files which are shared from another application or internally
|
* 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.
|
* 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>()
|
val uriList = mutableListOf<Uri>()
|
||||||
if (intent.action == Intent.ACTION_SEND) {
|
if (intent.action == Intent.ACTION_SEND) {
|
||||||
IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)
|
IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)
|
||||||
|
|
@ -115,9 +115,12 @@ class DefaultShareIntentHandler @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uriList.map { uri ->
|
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(
|
ShareIntentHandler.UriToShare(
|
||||||
uri = uri,
|
uri = uri,
|
||||||
mimeType = type
|
mimeType = mimeType,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue