B4A Library SimCard ( also Dual Sim )

MarcoRome

Expert
Licensed User
Longtime User
You can try also this ( Library Phone B4A )

B4X:
    Dim pId As PhoneId
    Log( pId.GetLine1Number )
 

yuhong

Member
Licensed User
Longtime User
GetSubscriberId,
Take the second card does not support for the IMSI.

regards.
 
Last edited:

yuhong

Member
Licensed User
Longtime User
Thank you very much for help,Now ,i invoke sim.GetSimSerialNumber2, fetch null value.
In fact, i inserted two sim cards.
Device:Xiaomi
Model No:HM NOTE 1S
android :4.4.4
CPU:Qualcomm MSM8916
 

Attachments

  • MI_20160112_120247.jpg
    78 KB · Views: 316
Last edited:

fabricio

Member
Licensed User
Longtime User
I try test lib:

B4A version: 5.80
Parsing code. (0.00s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Generating R file. (0.42s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\telephonyinfo.jar
 

MarcoRome

Expert
Licensed User
Longtime User

You found this file telephonyinfo.jar in library Rel.1. Now i have add also in 2
 

stratus

Active Member
Licensed User
Longtime User
I have a problem with getline1number.The result is the serialsimnumber and not the line number.Is there any way to get the simline number?
Thanks
 

MarcoRome

Expert
Licensed User
Longtime User
can i get GetSimOperatorName for sim 2??

There was no native support for multiple SIMs in Android before API 22 ( Andordi 5.1 or > ). Solutions will vary depending on the manufacturer/vendor.

Now you have JavaObejct Library that is very very power. So you can call method or another thing in very simple mode.
As suggestion to @Erel in this POST you can use this code:

B4X:
    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
        Log(info.RunMethod("getCarrierName", Null)) 'Operator Name
    Next

 

Mikonios

Active Member
Licensed User
Longtime User
Everything seems correct. It compiles and executes without errors but the telephone number that it gives does not match anywhere near the telephone number of the device !!!
Why ???


 

MarcoRome

Expert
Licensed User
Longtime User
Everything seems correct. It compiles and executes without errors but the telephone number that it gives does not match anywhere near the telephone number of the device !!!
Why ???


View attachment 93546


Try PhoneId.GetLine1Number (Phone library).
If you have same result read this:
 

MarcoRome

Expert
Licensed User
Longtime User
Hi MarcoRome,

I think the value of GetLine1Number and GetLine2Number are the IMEI's, not the phone numbers
No.

B4X:
/**
* Reads NumberPhone-1 and returns its content as a string.
*Example:<code>
*Dim sim As SimCard
*Dim text As String
*text = sim.GetLine1Number</code>
*/
  public String GetLine1Number() {
     String telephoneNumber = telephonyInfo.getNumberline1();
        if (telephoneNumber != null && telephoneNumber.charAt(0) == '+') {
            telephoneNumber=telephoneNumber.substring(1);
        }
        if (telephoneNumber != null && telephoneNumber.length() > 10 && telephoneNumber.charAt(0) == '1') {
            telephoneNumber=telephoneNumber.substring(1);
        }
     return telephonyInfo.getNumberline1();
    }

    

/**
* Reads NumberPhone-2 and returns its content as a string.
*Example:<code>
* Note: Utilize sim.IsDualSIM
*Dim sim As SimCard
*Dim text As String
*text = sim.GetLine2Number</code>
*/
  public String GetLine2Number() {
     String telephoneNumber = telephonyInfo.getNumberline2();
        if (telephoneNumber != null && telephoneNumber.charAt(0) == '+') {
            telephoneNumber=telephoneNumber.substring(1);
        }
        if (telephoneNumber != null && telephoneNumber.length() > 10 && telephoneNumber.charAt(0) == '1') {
            telephoneNumber=telephoneNumber.substring(1);
        }
     return telephonyInfo.getNumberline2();
    }
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…