[Android] Fix intent mime type when sharing media

Nicolas Pomepuy git at videolan.org
Fri Oct 11 10:20:19 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Oct 10 10:05:33 2024 +0200| [25170a13b0a78efd0f75bd7aaca2ddc5839ed5ef] | committer: Duncan McNamara

Fix intent mime type when sharing media

Fixes #3086

> https://code.videolan.org/videolan/vlc-android/commit/25170a13b0a78efd0f75bd7aaca2ddc5839ed5ef
---

 application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 6e38cb4e28..5fb7dd3249 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -135,16 +135,19 @@ fun FragmentActivity.share(medias: List<MediaWrapper>) = lifecycleScope.launch {
     val intentShareFile = Intent(Intent.ACTION_SEND_MULTIPLE)
     val uris = arrayListOf<Uri>()
     val title = if (medias.size == 1) medias[0].title else resources.getQuantityString(R.plurals.media_quantity, medias.size, medias.size)
+    var hasVideo = false
+    var hasAudio = false
     withContext(Dispatchers.IO) {
         medias.filter { it.uri.path != null && File(it.uri.path!!).exists() }.forEach {
             val file = File(it.uri.path!!)
+            if (it.type == TYPE_VIDEO) hasVideo = true else hasAudio = true
             uris.add(FileProvider.getUriForFile(this at share, "$packageName.provider", file))
         }
     }
 
     if (isStarted())
         if (uris.isNotEmpty()) {
-            intentShareFile.type = "*/*"
+            intentShareFile.type = if (hasAudio && !hasVideo) "audio/*" else if(hasVideo && !hasAudio) "video/*" else "*/*"
             intentShareFile.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
             intentShareFile.putExtra(Intent.EXTRA_SUBJECT, title)
             intentShareFile.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_message, title))



More information about the Android mailing list