Android Question B4A libraries / Code for Dual Sim phones for sending SMS / Calls / Data using specific sim ?

atulindore

Member
Licensed User
Longtime User
Dear Experts

In my app want to identify different sim operators in case phone is dual sim and want to use specific sim for sending SMS or using data services .

Pls suggest ..
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Start with this code:
B4X:
Sub TestSim
   Dim manager As JavaObject
   Dim context As JavaObject
   context.InitializeContext
   manager = manager.InitializeStatic("android.telephony.SubscriptionManager").RunMethod("from", Array(context))
   Dim infos As List = manager.RunMethod("getActiveSubscriptionInfoList", Null)
   For Each info As JavaObject In infos
     Log(info)
     'work with info
     'http://developer.android.com/reference/android/telephony/SubscriptionInfo.html
   Next
End Sub
Add this line to the manifest editor:
B4X:
AddPermission(android.permission.READ_PHONE_STATE)
 
Upvote 0

atulindore

Member
Licensed User
Longtime User
context.InitializeContext giving error "Unknown member : InitializeContext"

i am using Java object lib v 1.25 and b4a v 3.8
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
I would like to get the SIM Serial numbers of both the SIM cards in a Dual SIM phone. Is this possible using B4A ?

I tried using the Library https://www.b4x.com/android/forum/threads/simcard-also-dual-sim.51301/#post-321164
Unfortunately the lib gives IMEI numbers as SIM Serial Numbers and Line Numbers.

I tried the code posted by Erel in this thread. It is reading both the SIM's serial numbers in the column named iccId, unfortunately only the first 9 characters are displayed, the rest are shown as XXXXXXX. It is supposed to be 19 characters.

I mean this code
B4X:
Sub TestSim
   Dim manager As JavaObject
   Dim context As JavaObject
   context.InitializeContext
   manager = manager.InitializeStatic("android.telephony.SubscriptionManager").RunMethod("from", Array(context))
   Dim infos As List = manager.RunMethod("getActiveSubscriptionInfoList", Null)
   For Each info As JavaObject In infos
     Log(info)
     'work with info
     'http://developer.android.com/reference/android/telephony/SubscriptionInfo.html
   Next
End Sub

I inserted the Log(info) into a list view. It is displaying 2 records, 1 for each SIM
 
Last edited:
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
B4X:
Log(info.RunMethod("getDisplayName", Null))
Log(info.RunMethod("getNumber", Null))

It is working fine on Lolipop. Unfortunately when I tested on Android 4.4.2, I got the following error message.

B4X:
java.lang.ClassNotFoundException:
android$telephony$SubscriptionManager

Does it means that this will work only on Lollipop or above ?
Is there any way that this can be made working on all android versions, atleast above Android ver 4
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Search with Google to find out on which android the subscriptionmanager is added
 
Upvote 0
Top