B4A Library SimCard ( also Dual Sim )

Discussion in 'Additional libraries, classes and official updates' started by MarcoRome, Mar 1, 2015.

  1. MarcoRome

    MarcoRome Expert Licensed 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.

    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:

    Code:
    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
     

    Attached Files:

    Last edited: Sep 5, 2015
  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

  3. Enrico79

    Enrico79 Member Licensed 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>
     
  4. MarcoRome

    MarcoRome Expert Licensed User

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

    Sorin Pohontu Member Licensed User

    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
     
    pesquera and MarcoRome like this.
  6. atulindore

    atulindore Member Licensed 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: Jun 13, 2015
    koaunglay likes this.
  7. G-ShadoW

    G-ShadoW Active Member Licensed User

    Error when try to compile...
     

    Attached Files:

  8. MarcoRome

    MarcoRome Expert Licensed User

    I dont know why ..but seem more error Java ( i use 1.7.0_67 the same ).
    Look here
     
  9. G-ShadoW

    G-ShadoW Active Member Licensed 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.
     
  10. G-ShadoW

    G-ShadoW Active Member Licensed User

    where is Log 12 or 21 ? :D
     
  11. MarcoRome

    MarcoRome Expert Licensed User

    Dont like this number ;)
     
  12. PoleStar

    PoleStar Member Licensed User

    Hi
    my activity name is: ac2
    and my code is :
    Code:
    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
     

    Attached Files:

  13. G-ShadoW

    G-ShadoW Active Member Licensed 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.
     
    PoleStar likes this.
  14. MarcoRome

    MarcoRome Expert Licensed User

    Hi Pantea you forget this

    Code:
    sim.Initialize()
    Code:
    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
     
    PoleStar likes this.
  15. G-ShadoW

    G-ShadoW Active Member Licensed User

    This is how it's look like
     

    Attached Files:

    PoleStar likes this.
  16. PoleStar

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

    Attached Files:

  17. G-ShadoW

    G-ShadoW Active Member Licensed User

    To avoid crashes you should make it like this...

    Code:
    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...
     
  18. MarcoRome

    MarcoRome Expert Licensed User

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

    MarcoRome Expert Licensed User

    Pantea try this in your mobile.
     

    Attached Files:

  20. G-ShadoW

    G-ShadoW Active Member Licensed User

    It's samsung mobile phone at it will crash for sure

    Code:
    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?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice