From 1cb30ec8bb04c1f594d5548392b8d5754887fc3f Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Mon, 7 Aug 2023 18:52:06 +0200 Subject: [PATCH] Glimpse: Try to set proper mime type when sharing media We also have to grant read URI permission in case the receiving end doesn't have the read media permission. Change-Id: I28b77b680bdff123a0c737eb41ddcdbe34dba1cb --- .../java/org/lineageos/glimpse/ext/Intent.kt | 17 +++++++++++++---- .../glimpse/fragments/MediaViewerFragment.kt | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt index 32c3061..ac69b6b 100644 --- a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt +++ b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt @@ -6,13 +6,22 @@ package org.lineageos.glimpse.ext import android.content.Intent -import android.net.Uri import org.lineageos.glimpse.models.Media +import org.lineageos.glimpse.models.MediaType.IMAGE +import org.lineageos.glimpse.models.MediaType.VIDEO -fun Intent.shareIntent(vararg uris: Uri) = apply { +fun Intent.shareIntent(vararg medias: Media) = apply { action = Intent.ACTION_SEND_MULTIPLE - putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris.toCollection(ArrayList())) - type = "*/*" + putParcelableArrayListExtra( + Intent.EXTRA_STREAM, + medias.map { it.externalContentUri }.toCollection(ArrayList()) + ) + type = when { + medias.all { it.mediaType == IMAGE } -> "image/*" + medias.all { it.mediaType == VIDEO } -> "video/*" + else -> "*/*" + } + flags = Intent.FLAG_GRANT_READ_URI_PERMISSION } fun Intent.editIntent(media: Media) = apply { diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt index cd7ea09..16cb8ea 100644 --- a/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt +++ b/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt @@ -280,7 +280,7 @@ class MediaViewerFragment : Fragment( shareButton.setOnClickListener { mediaViewerAdapter.getMediaFromMediaStore(viewPager.currentItem)?.let { - val intent = Intent().shareIntent(it.externalContentUri) + val intent = Intent().shareIntent(it) startActivity(Intent.createChooser(intent, null)) } }