From 84ad32a65e545cb2688667f14965adb78bea26da Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 31 Mar 2026 14:27:03 +0200 Subject: [PATCH] Fixed sharing text multiple times from a third party app to Linphone not working after first one --- .../java/org/linphone/ui/main/MainActivity.kt | 23 +++++++++++-------- .../chat/fragment/ConversationFragment.kt | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/main/MainActivity.kt b/app/src/main/java/org/linphone/ui/main/MainActivity.kt index f50b4cd9d..f10149c4f 100644 --- a/app/src/main/java/org/linphone/ui/main/MainActivity.kt +++ b/app/src/main/java/org/linphone/ui/main/MainActivity.kt @@ -642,15 +642,6 @@ class MainActivity : GenericActivity() { private fun handleSendIntent(intent: Intent, multiple: Boolean) { val parcelablesUri = arrayListOf() - - if (intent.type == "text/plain") { - Log.i("$TAG Intent type is [${intent.type}], expecting text in Intent.EXTRA_TEXT") - intent.getStringExtra(Intent.EXTRA_TEXT)?.let { extraText -> - Log.i("$TAG Found extra text in intent, long of [${extraText.length}]") - sharedViewModel.textToShareFromIntent.value = extraText - } - } - if (multiple) { val parcelables = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM) @@ -698,11 +689,23 @@ class MainActivity : GenericActivity() { if (path != null) list.add(path) } + var textToShare = "" + if (intent.type == "text/plain") { + Log.i("$TAG Intent type is [${intent.type}], expecting text in Intent.EXTRA_TEXT") + textToShare = intent.getStringExtra(Intent.EXTRA_TEXT).orEmpty() + if (textToShare.isEmpty()) { + Log.e("$TAG Intent.EXTRA_TEXT not found in intent!") + } else { + Log.i("$TAG Found extra text in intent, long of [${textToShare.length}]") + } + } + if (list.isNotEmpty()) { sharedViewModel.filesToShareFromIntent.value = list } else { - if (sharedViewModel.textToShareFromIntent.value.orEmpty().isNotEmpty()) { + if (textToShare.isNotEmpty()) { Log.i("$TAG Found plain text to share") + sharedViewModel.textToShareFromIntent.value = textToShare } else { Log.w("$TAG Failed to find at least one file or text to share!") } diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt index 3a2b156d2..02935e759 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt @@ -1002,7 +1002,7 @@ open class ConversationFragment : SlidingPaneChildFragment() { } sharedViewModel.textToShareFromIntent.observe(viewLifecycleOwner) { text -> - if (text.isNotEmpty()) { + if (text.isNotEmpty() && sharedViewModel.displayedChatRoom != null) { Log.i("$TAG Found text to share from intent") sendMessageViewModel.textToSend.value = text