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: 1,256
  • Example-SimCard2.zip
    8.7 KB · Views: 1,189
  • Library-SimCard2a.zip
    11.3 KB · Views: 1,184
Last edited:

Enrico79

Member
Licensed User
Longtime User
Hey MarcoRome!

The IsSIM2Ready function is not available! How to use it?

The IsDualSIM function does not work for me on some Devices (Samsung Galaxy S4 mini Dualsim and Acer Liquid E3 Plus Dualsim)

Log 3 and log 25 is the same?!

  • 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>
 

MarcoRome

Expert
Licensed User
Longtime User
Hey MarcoRome!

The IsSIM2Ready function is not available! How to use it?

The IsDualSIM function does not work for me on some Devices (Samsung Galaxy S4 mini Dualsim and Acer Liquid E3 Plus Dualsim)

Log 3 and log 25 is the same?!

  • 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>

Hi Enrico. Strain that dont work.
This is result :
Screenshot 2015-03-29 18.19.08.png
 

Sorin Pohontu

Member
Licensed User
Longtime User
The IsDualSIM function does not work for me on some Devices (Samsung Galaxy S4 mini Dualsim and Acer Liquid E3 Plus Dualsim)

As I know, dual SIM checks are based on Gemini class checks, which means Mediatek (MTK) processor based devices.
Samsung Galaxy S4 mini Dualsim and Acer Liquid E3 Plus Dualsim are Qualcomm based processor, and these devices will not be detected as Dual SIM.

Have a nice day,
/Sorin
 

atulindore

Member
Licensed User
Longtime User
Hi MarcoRome
How can i select sim 1/ sim2 for sending SMS ..
and sim operator name is showing name for only primary sim .
 
Last edited:

G-ShadoW

Active Member
Licensed User
Longtime User
Funny, I have changed Activity name and it worked, but application crashes when it cant read info from card,
so I suggest Try, Catch for all option's to avoid crashing app.

B.R.
 

G-ShadoW

Active Member
Licensed User
Longtime User
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.

B4X:
sim.Initialize()
    Log("1: - " & sim.GetDataActivity)
    Log("2: - " & sim.GetDataState)
    Log("3: - " & sim.GetLine1Number)
    Log("4: - " & sim.GetMmsAgent)
    Log("5: - " & sim.GetMmsURL)
    Log("6: - " & sim.GetNetworkCountryIso)
    Log("7: - " & sim.GetNetworkOperator)
    Log("8: - " & sim.GetPhoneType)
    Log("9: - " & sim.GetSimCountryIso)
    Log("10: - " & sim.GetSimOperator)
    Log("11: - " & 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.IsNetworkRoaming)
    Log("20: - " & sim.IsDualSIM)
    Log("22: - " & sim.Imei2)
    Log("23: - " & sim.GetSimSerialNumber1)
    Log("24: - " & sim.GetSimSerialNumber2)
    Log("25: - " & sim.GetLine2Number)
    Log("26: - " & sim.GetNetworkOperatorName)

where is Log 12 or 21 ? :D
 

PoleStar

Member
Licensed User
Longtime User
Hi
my activity name is: ac2
and my code is :
B4X:
Sub Globals

    Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout2")
    Dim sim As SimCard
    Dim text As String
    text = sim.GetLine1Number
    EditText1.Text = text
End Sub

when running app in emulator and my mobile i shown this error.
also , i use try catch to avoid the error but don't work it
i using java jdk1.7.0_40
 

Attachments

  • java-error.PNG
    java-error.PNG
    44.2 KB · Views: 336

G-ShadoW

Active Member
Licensed User
Longtime User
Can you post source code?
In most cases you will not be able to read SIM number, it will display your IMEI number insted.
 

MarcoRome

Expert
Licensed User
Longtime User
Hi
my activity name is: ac2
and my code is :
B4X:
Sub Globals

    Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout2")
    Dim sim As SimCard
    Dim text As String
    text = sim.GetLine1Number
    EditText1.Text = text
End Sub

when running app in emulator and my mobile i shown this error.
also , i use try catch to avoid the error but don't work it
i using java jdk1.7.0_40

Hi Pantea you forget this

B4X:
sim.Initialize()

B4X:
    Activity.LoadLayout("Layout2")
    Dim sim As SimCard
    sim.Initialize() ' <------ ADD THIS IN YOUR CODE
    Dim text As String
    text = sim.GetLine1Number
    EditText1.Text = text

Bye
 

G-ShadoW

Active Member
Licensed User
Longtime User
This is how it's look like
 

Attachments

  • Screenshot_2015-08-22-16-15-28.png
    Screenshot_2015-08-22-16-15-28.png
    62.7 KB · Views: 396
  • Screenshot_2015-08-22-16-16-34.png
    Screenshot_2015-08-22-16-16-34.png
    57.3 KB · Views: 377
  • Screenshot_2015-08-22-16-17-15.png
    Screenshot_2015-08-22-16-17-15.png
    61.4 KB · Views: 417

PoleStar

Member
Licensed User
Longtime User
Hi Pantea you forget this

B4X:
sim.Initialize()

B4X:
    Activity.LoadLayout("Layout2")
    Dim sim As SimCard
    sim.Initialize() ' <------ ADD THIS IN YOUR CODE
    Dim text As String
    text = sim.GetLine1Number
    EditText1.Text = text

Bye

thanks a lot for your quick answer.
this problem solved in my emulator
also , all voids work in my cellphone ( Sumsong Galexy Grand - Android 4.2.2 )
but GetLine1Number is dos'nt work and shown this new error
 

Attachments

  • Screenshot_2015-08-22-19-02-10.png
    Screenshot_2015-08-22-19-02-10.png
    49.8 KB · Views: 273

G-ShadoW

Active Member
Licensed User
Longtime User
To avoid crashes you should make it like this...

B4X:
Try
    Log("1: - Data activity: " & sim.GetDataActivity)
    EDSimInfo.Text= EDSimInfo.Text & "1: - Data activity: " & sim.GetDataActivity & CRLF
    Catch
    Log("GetDataActivity: " & LastException.Message)
    End Try
   
    Try
    Log("2: - Data state: " & sim.GetDataState)
    EDSimInfo.text=EDSimInfo.Text & "2: - Data state: " & sim.GetDataState & CRLF
    Catch
    Log("GetDataState: " & LastException.Message)
    End Try
   
    Try
    Log("3: - Line1 Number: " & sim.GetLine1Number)
    EDSimInfo.text=EDSimInfo.Text & "3: - Line1 Number: " & sim.GetLine1Number & CRLF
    Catch
    Log("GetLine1Number: " & LastException.Message)
    End Try

etc...
 

MarcoRome

Expert
Licensed User
Longtime User
thanks a lot for your quick answer.
this problem solved in my emulator
also , all voids work in my cellphone ( Sumsong Galexy Grand - Android 4.2.2 )
but GetLine1Number is dos'nt work and shown this new error

Do you've tried the example to post #1 with your phone ( no emulator ) ?
 

MarcoRome

Expert
Licensed User
Longtime User
thanks a lot for your quick answer.
this problem solved in my emulator
also , all voids work in my cellphone ( Sumsong Galexy Grand - Android 4.2.2 )
but GetLine1Number is dos'nt work and shown this new error

Pantea try this in your mobile.
 

Attachments

  • testsimcard2.zip
    8.8 KB · Views: 407

G-ShadoW

Active Member
Licensed User
Longtime User
It's samsung mobile phone at it will crash for sure

B4X:
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (ac2) Create, isFirst = true **
ac2_activity_create (B4A line: 25)
text = sim.GetLine1Number
java.lang.StringIndexOutOfBoundsException: length=0; index=0
    at java.lang.String.charAt(Native Method)
    at simcard.SimCard.GetLine1Number(SimCard.java:133)
    at b4a.example.ac2._activity_create(ac2.java:345)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at b4a.example.ac2.afterFirstLayout(ac2.java:100)
    at b4a.example.ac2.access$100(ac2.java:17)
    at b4a.example.ac2$WaitForLayout.run(ac2.java:78)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4963)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)

maybe you can add in your library try catch option to avoid that?
 
Top