From 96ce1eabcd0bb36ca44a710a2efad8b78769ca02 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 May 2020 16:45:18 +0200 Subject: [PATCH] handle the SIM picking before calling only if this is the default dialer app --- .../contacts/pro/extensions/Activity.kt | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index 354fa41a..99f13307 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -21,17 +21,29 @@ import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.models.Contact fun SimpleActivity.startCallIntent(recipient: String) { + if (isDefaultDialer()) { + getHandleToUse(null, recipient) { handle -> + launchCallIntent(recipient, handle) + } + } else { + launchCallIntent(recipient, null) + } +} + +fun SimpleActivity.launchCallIntent(recipient: String, handle: PhoneAccountHandle?) { handlePermission(PERMISSION_CALL_PHONE) { val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL - getHandleToUse(null, recipient) { handle -> - Intent(action).apply { - data = Uri.fromParts("tel", recipient, null) + Intent(action).apply { + data = Uri.fromParts("tel", recipient, null) + + if (handle != null) { putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + } + + if (resolveActivity(packageManager) != null) { + startActivity(this) + } else { + toast(R.string.no_app_found) } } }