diff --git a/android/src/main/kotlin/com/kasem/receive_sharing_intent/ReceiveSharingIntentPlugin.kt b/android/src/main/kotlin/com/kasem/receive_sharing_intent/ReceiveSharingIntentPlugin.kt index 21d2bbd0..5acbd53a 100644 --- a/android/src/main/kotlin/com/kasem/receive_sharing_intent/ReceiveSharingIntentPlugin.kt +++ b/android/src/main/kotlin/com/kasem/receive_sharing_intent/ReceiveSharingIntentPlugin.kt @@ -113,7 +113,8 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl private fun handleIntent(intent: Intent, initial: Boolean) { when { (intent.type?.startsWith("text") != true) - && (intent.action == Intent.ACTION_SEND + && (intent.action == Intent.ACTION_VIEW + || intent.action == Intent.ACTION_SEND || intent.action == Intent.ACTION_SEND_MULTIPLE) -> { // Sharing images or videos val value = getMediaUris(intent) @@ -137,25 +138,32 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl } } + private fun getMediaFromUri(uri: Uri): JSONArray? { + val path = FileDirectory.getAbsolutePath(applicationContext, uri) + + return if (path != null) { + val type = getMediaType(path) + val thumbnail = getThumbnail(path, type) + val duration = getDuration(path, type) + JSONArray().put( + JSONObject() + .put("path", path) + .put("type", type.ordinal) + .put("thumbnail", thumbnail) + .put("duration", duration) + ) + } else null + } + private fun getMediaUris(intent: Intent?): JSONArray? { if (intent == null) return null return when (intent.action) { + Intent.ACTION_VIEW -> { + return getMediaFromUri(intent.getData()) + } Intent.ACTION_SEND -> { - val uri = intent.getParcelableExtra(Intent.EXTRA_STREAM) - val path = uri?.let{ FileDirectory.getAbsolutePath(applicationContext, it) } - if (path != null) { - val type = getMediaType(path) - val thumbnail = getThumbnail(path, type) - val duration = getDuration(path, type) - JSONArray().put( - JSONObject() - .put("path", path) - .put("type", type.ordinal) - .put("thumbnail", thumbnail) - .put("duration", duration) - ) - } else null + return getMediaFromUri(intent.getParcelableExtra(Intent.EXTRA_STREAM)) } Intent.ACTION_SEND_MULTIPLE -> { val uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)