From 9136be68b3c5ad50b9497520ecd88354165552df Mon Sep 17 00:00:00 2001 From: tomsqrd Date: Sat, 22 Nov 2025 12:03:30 +0100 Subject: [PATCH] Reading the optional String extras from attachment share intents (#9396) and adding them to the compose intents for images and videos if they exist. Co-authored-by: Tom Quinders --- .../ExpoReceiveAndroidIntentsModule.kt | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt index bee835247c..2aaee3b8ec 100644 --- a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt +++ b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt @@ -78,10 +78,12 @@ class ExpoReceiveAndroidIntentsModule : Module() { intent.getParcelableExtra(Intent.EXTRA_STREAM) } + val text = intent.getStringExtra(Intent.EXTRA_TEXT) + uri?.let { when (type) { - AttachmentType.IMAGE -> handleImageIntents(listOf(it)) - AttachmentType.VIDEO -> handleVideoIntents(listOf(it)) + AttachmentType.IMAGE -> handleImageIntents(listOf(it), text) + AttachmentType.VIDEO -> handleVideoIntents(listOf(it), text) } } } @@ -103,15 +105,20 @@ class ExpoReceiveAndroidIntentsModule : Module() { ?.take(4) } + val text = intent.getStringExtra(Intent.EXTRA_TEXT) + uris?.let { when (type) { - AttachmentType.IMAGE -> handleImageIntents(it) + AttachmentType.IMAGE -> handleImageIntents(it, text) else -> return } } } - private fun handleImageIntents(uris: List) { + private fun handleImageIntents( + uris: List, + text: String? + ) { var allParams = "" uris.forEachIndexed { index, uri -> @@ -124,15 +131,22 @@ class ExpoReceiveAndroidIntentsModule : Module() { } } - val encoded = URLEncoder.encode(allParams, "UTF-8") + val encodedUris = URLEncoder.encode(allParams, "UTF-8") + val encodedText = text?.let { URLEncoder.encode(it, "UTF-8") } - "bluesky://intent/compose?imageUris=$encoded".toUri().let { + var composeIntent = "bluesky://intent/compose?imageUris=$encodedUris" + encodedText?.let { composeIntent += "&text=$it" } + + composeIntent.toUri().let { val newIntent = Intent(Intent.ACTION_VIEW, it) appContext.currentActivity?.startActivity(newIntent) } } - private fun handleVideoIntents(uris: List) { + private fun handleVideoIntents( + uris: List, + text: String? + ) { val uri = uris[0] // If there is no extension for the file, substringAfterLast returns the original string - not // null, so we check for that below @@ -151,7 +165,12 @@ class ExpoReceiveAndroidIntentsModule : Module() { val info = getVideoInfo(uri) ?: return - "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}|${info["width"]}|${info["height"]}".toUri().let { + val encodedText = text?.let { URLEncoder.encode(it, "UTF-8") } + + var composeIntent = "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}|${info["width"]}|${info["height"]}" + encodedText?.let { composeIntent += "&text=$it" } + + composeIntent.toUri().let { val newIntent = Intent(Intent.ACTION_VIEW, it) appContext.currentActivity?.startActivity(newIntent) }