Hi, All
This my code calls OK by both SIM-cards on Samsung A7 device. Try and reply here, if works on your device.
Requirements: minSdkVersion="23" (Android 6); 2 working SIM-cards.
Inspired by: https://www.b4x.com/android/forum/threads/call-from-dual-sim.99801/#post-628156
This my code calls OK by both SIM-cards on Samsung A7 device. Try and reply here, if works on your device.
B4X:
Sub Activity_Resume
For Each permission As String In Permissions
If rp.Check(permission) = False Then
Sleep(200)
rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
Log(permission)
If Result = False Then
ToastMessageShow("No permission " & permission, True)
rp.CheckAndRequest(permission)
Sleep(200)
Return
End If
End If
Next
If FirstInit Then
FirstInit = False
spSIMnum.Clear
spSIMnum.Add("SIM1")
butCall.Text = "Call by " & spSIMnum.SelectedItem
Dim j As JavaObject
j.InitializeContext
Dim telMgr As JavaObject = j.RunMethod("getSystemService", Array("phone"))
Dim PhoneCount As Int = telMgr.RunMethod("getPhoneCount", Null)
If PhoneCount >= 2 Then
spSIMnum.Add("SIM2")
End If
End If
Get_Tel_Accounts
End Sub
Sub Get_Tel_Accounts
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim telecom As JavaObject = ctxt.RunMethod("getSystemService", Array("telecom"))
Dim accounts As List = telecom.RunMethod("getCallCapablePhoneAccounts", Null)
'Log(accounts) '(ArrayList) [ComponentInfo{com.android.phone/com.android.services.telephony.TelephonyConnectionService}, [****], UserHandle{0}, ComponentInfo{com.android.phone/com.android.services.telephony.TelephonyConnectionService}, [****], UserHandle{0}]
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
'sim = 0 SIM1, = 1 SIM2
Sub Call_SIM(num As String, sim As Int)
Dim i As Intent
i.Initialize(i.ACTION_CALL, "tel:" & num)
i.putExtra("simSlot", sim)
i.putExtra("com.android.phone.force.slot", True)
i.putExtra("Cdma_Supp", True)
i.putExtra("com.android.phone.extra.slot", sim)
If accounts.IsInitialized Then
If accounts.Size > 0 Then
i.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", accounts.Get(sim))
End If
End If
StartActivity(i)
End Sub
Sub butCall_Click
If txtTelNum.Text.Trim = "" Then Return
If spSIMnum.SelectedIndex < 0 Then Return
Call_SIM(txtTelNum.Text, spSIMnum.SelectedIndex)
End Sub
Sub spSIMnum_ItemClick (Position As Int, Value As Object)
butCall.Text = "Call by " & spSIMnum.SelectedItem
End Sub
Requirements: minSdkVersion="23" (Android 6); 2 working SIM-cards.
Inspired by: https://www.b4x.com/android/forum/threads/call-from-dual-sim.99801/#post-628156
Attachments
Last edited: