From 9496999773066d1692099f5e7ebe8b3689e56350 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 27 Nov 2023 15:58:12 +0100 Subject: [PATCH] Added back intent filter for dialing tel, sip or sips URI --- app/src/main/AndroidManifest.xml | 11 ++++++ .../java/org/linphone/ui/main/MainActivity.kt | 35 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c6e8f0cfb..2a97f4120 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -87,6 +87,17 @@ + + + + + + + + + + + { handleSendIntent(intent, true) } + Intent.ACTION_VIEW, Intent.ACTION_DIAL, Intent.ACTION_CALL -> { + handleCallIntent(intent) + } } } + @MainThread private fun handleMainIntent(intent: Intent, defaultDestination: Int, isNewIntent: Boolean) { val navGraph = findNavController().navInflater.inflate(R.navigation.main_nav_graph) if (intent.hasExtra("Chat")) { @@ -373,6 +379,7 @@ class MainActivity : GenericActivity() { } } + @MainThread private fun handleSendIntent(intent: Intent, multiple: Boolean) { val parcelablesUri = arrayListOf() @@ -462,6 +469,34 @@ class MainActivity : GenericActivity() { } } + @MainThread + private fun handleCallIntent(intent: Intent) { + val uri = intent.data?.toString() + if (uri.isNullOrEmpty()) { + Log.e("$TAG Intent data is null or empty, can't process [${intent.action}] intent") + return + } + + Log.i("$TAG Found URI [$uri] as data for intent [${intent.action}]") + val sipUriToCall = if (uri.startsWith("tel:")) { + uri.substring("tel:".length) + } else { + uri + }.replace("%40", "@") // Unescape @ character if needed + + coreContext.postOnCoreThread { + val applyPrefix = LinphoneUtils.getDefaultAccount()?.params?.useInternationalPrefixForCallsAndChats ?: false + val address = coreContext.core.interpretUrl( + sipUriToCall, + applyPrefix + ) + Log.i("$TAG Interpreted SIP URI is [${address?.asStringUriOnly()}]") + if (address != null) { + coreContext.startCall(address) + } + } + } + private fun loadContacts() { coreContext.contactsManager.loadContacts(this)