B4A Library SimCard ( also Dual Sim )

This library reads the sim (both, also dual sim), example Serial Number SIM-1 and SIM-2, Number Phone SIM-1 and SIM-2, etc.

simcard.png



SimCard
Author:
Devil-App
Version: 2
  • SimCard
    Methods:
    • GetDataActivity As String
      Returns a constant indicating the type of activity on a data connection (cellular).
      Return DATA_ACTIVITY_NONE
      Return DATA_ACTIVITY_IN
      Return DATA_ACTIVITY_OUT
      Return DATA_ACTIVITY_INOUT
      Return DATA_ACTIVITY_DORMANT
      Example:<code>
      Dim sim As SimCard
      Dim torna As String
      torna = sim.GetDataActivity </code>
    • GetDataState As String
      Returns a constant indicating the current data connection state (cellular).
      Return DATA_DISCONNECTED
      Return DATA_CONNECTING
      Return DATA_CONNECTED
      Return DATA_SUSPENDED
      Example:<code>
      Dim sim As SimCard
      Dim torna As String
      torna = sim.GetDataState </code>
    • GetLine1Number As String
      Reads NumberPhone-1 and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetLine1Number</code>
    • GetLine2Number As String
      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>
    • GetMmsAgent As String
      Reads MMS user Agent and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetMmsAgent</code>
    • GetMmsURL As String
      Reads MMS user Agent profile URL and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetMmsURL</code>
    • GetNetworkCountryIso As String
      Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code) and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetNetworkCountryIso</code>
    • GetNetworkOperator As String
      Returns the numeric name (MCC+MNC) of current registered operator and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetNetworkOperator</code>
    • GetNetworkOperatorName As String
      Returns the operator name (MCC+MNC) of current registered operator and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetNetworkOperator</code>
    • GetPhoneType As String
      Returns a constant indicating the device phone type. This indicates the type of radio used to transmit voice calls.
      Return PHONE_TYPE_NONE
      Return PHONE_TYPE_GSM
      Return PHONE_TYPE_CDMA
      Return PHONE_TYPE_SIP
      Example:<code>
      Dim sim As SimCard
      Dim torna As String
      torna = sim.GetPhoneType </code>
    • GetSimCountryIso As String
      Returns the ISO country code equivalent for the SIM provider's country code and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetSimCountryIso</code>
    • GetSimOperator As String
      Returns the MCC+MNC (mobile country code + mobile network code) of the provider of the SIM. and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetSimOperator</code>
    • GetSimOperatorName As String
      Returns the Service Provider Name (SPN) and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetSimOperatorName</code>
    • GetSimSerialNumber1 As String
      Returns the serial number of the SIM, if applicable and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetSimSerialNumber</code>
    • GetSimSerialNumber2 As String
      Returns the serial number of the SIM-2, if applicable and returns its content as a string.
      Example:<code>
      Note: Utilize sim.IsDualSIM
      Dim sim As SimCard
      Dim text As String
      text = sim.GetSimSerialNumber</code>
    • GetSimState As String
      Returns a constant indicating the state of the device SIM card.
      Return SIM_STATE_UNKNOWN
      Return SIM_STATE_ABSENT - SIM card state: no SIM card is available in the device
      Return SIM_STATE_PIN_REQUIRED - SIM card state: Locked: requires the user's SIM PIN to unlock
      Return SIM_STATE_PUK_REQUIRED - SIM card state: Locked: requires the user's SIM PUK to unlock
      Return SIM_STATE_NETWORK_LOCKED - SIM card state: Locked: requries a network PIN to unlock
      Return SIM_STATE_READY
      Example:<code>
      Dim sim As SimCard
      Dim torna As String
      torna = sim.GetSimState </code>
    • GetSubscriberId As String
      Returns the unique subscriber ID, for example, the IMSI for a GSM phone and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetSubscriberId</code>
    • GetVoiceMailAlphaTag As String
      Retrieves the alphabetic identifier associated with the voice mail number and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetVoiceMailAlphaTag</code>
    • GetVoiceMailNumber As String
      Returns the voice mail number and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.GetVoiceMailNumber </code>
    • HasIccCard As Boolean
      Returns true if a ICC card is present.
      Example:<code>
      Dim sim As SimCard
      Dim vero As boolean
      vero = sim.HasIccCard </code>
    • Imei As String
      Reads IMEI for GSM and the MEDI or ESN for CDMA phones and returns its content as a string.
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.Imei</code>
    • Imei2 As String
      Reads IMEI2 for GSM and the MEDI or ESN for CDMA phones and returns its content as a string.
      Note: Utilize sim.IsDualSIM and IsSIM2Ready
      Example:<code>
      Dim sim As SimCard
      Dim text As String
      text = sim.Imei2</code>
    • Initialize
      Initialize - <link>Documentation:|http://developer.android.com/refere...TelephonyManager.html#SIM_STATE_ABSENT</link>.
      Example:<code>
      Dim sim As SimCard
      sim.Initialize()</code>
    • IsDualSIM As Boolean
      Check if is DUAL SIM.
      Example:<code>
      Dim sim As SimCard
      Dim vero As boolean
      vero = sim.IsDualSIM</code>
    • IsNetworkRoaming As Boolean
      Returns true if the device is considered roaming on the current network, for GSM purposes.
      Example:<code>
      Dim sim As SimCard
      Dim vero As boolean
      vero = sim.IsNetworkRoaming </code>
    Permissions:
    • android.permission.READ_PHONE_STATE

Very simple to use:

B4X:
sim.Initialize()
    Log("1: - " & sim.GetDataActivity)
    Log("2: - " & sim.GetDataState)
    Log("3: - " & sim.GetLine1Number)
    Log("4: - " & sim.GetLine2Number)
    Log("5: - " & sim.GetMmsAgent)
    Log("6: - " & sim.GetMmsURL)
    Log("7: - " & sim.GetNetworkCountryIso)
    Log("8: - " & sim.GetNetworkOperator)
    Log("9: - " & sim.GetPhoneType)
    Log("10: - " & sim.GetSimCountryIso)
    Log("11: - " & sim.GetSimOperator)
    Log("12: - " & sim.GetSimOperatorName)
    Log("13: - " & sim.GetSimState)
    Log("14: - " & sim.GetSubscriberId)
    Log("15: - " & sim.GetVoiceMailAlphaTag)
    Log("16: - " & sim.GetVoiceMailNumber)
    Log("17: - " & sim.HasIccCard)
    Log("18: - " & sim.Imei)
    Log("19: - " & sim.Imei2)
    Log("20: - " & sim.IsNetworkRoaming)
    Log("21: - " & sim.IsDualSIM)
    Log("22: - " & sim.GetSimSerialNumber1)
    Log("23: - " & sim.GetSimSerialNumber2)
    Log("24: - " & sim.GetLine2Number)
    Log("25: - " & sim.GetNetworkOperatorName)

Rel 2 -- > ADD THIS
 

Attachments

  • Library-SimCard1.00.zip
    11.3 KB · Views: 899
  • Example-SimCard2.zip
    8.7 KB · Views: 847
  • Library-SimCard2a.zip
    11.3 KB · Views: 822
Last edited:

yuhong

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

regards.
 
Last edited:

yuhong

Member
Licensed 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
    MI_20160112_120247.jpg
    78 KB · Views: 145
Last edited:

fabricio

Member
Licensed 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
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

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

stratus

Active Member
Licensed 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
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

//*** carrierName = getNetworkOperatorName
// Get System TELEPHONY service reference
TelephonyManager tManager = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);

// Get carrier name (Network Operator Name)
String carrierName = tManager.getNetworkOperatorName();

// Get Phone model and manufacturer name
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
 

Mikonios

Active Member
Licensed 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 ???


1588880925938.png
 

MarcoRome

Expert
Licensed 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:
But remember, this code does not always work, since Cell phone number is dependent on the SIM Card and the Network operator / Cell phone carrier.

Also, try checking in Phone--> Settings --> About --> Phone Identity, If you are able to view the Number there, the probability of getting the phone number from above code is higher. If you are not able to view the phone number in the settings, then you won't be able to get via this code!

Suggested Workaround:

  1. Get the user's phone number as manual input from the user.
  2. Send a code to the user's mobile number via SMS.
  3. Ask user to enter the code to confirm the phone number.
  4. Save the number in sharedpreference.
Do the above 4 steps as one time activity during the app's first launch. Later on, whenever phone number is required, use the value available in shared preference.
( https://www.semicolonworld.com/question/48355/get-my-phone-number-in-android )
 

MarcoRome

Expert
Licensed 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();
    }
 
Top