Android Question Using TelephonyManager class

Discussion in 'Android Questions' started by ZarinPour, Jul 20, 2014.

  1. ZarinPour

    ZarinPour New Member

    Hi all
    I'm new to b4A (just some hours) and i wanted to make a sample to get SIM-CARD info
    here is the code in Eclipse IDE:



    Code:
    ...
    ....
    import android.content.Context;
    import android.telephony.TelephonyManager;
    .........

    TelephonyManager telMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        int simState = telMgr.getSimState();
                
    switch (simState) {
                    
    case TelephonyManager.SIM_STATE_ABSENT:
                        // 
    do something
                        break;
                    
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
                        // 
    do something
                        break;
                    
    case TelephonyManager.SIM_STATE_PIN_REQUIRED:
                        // 
    do something
                        break;
                    
    case TelephonyManager.SIM_STATE_PUK_REQUIRED:
                        // 
    do something
                        break;
                    
    case TelephonyManager.SIM_STATE_READY:
                        // 
    do something
                        break;
                    
    case TelephonyManager.SIM_STATE_UNKNOWN:
                        // 
    do something
                        break;
                
    }
    BUT i don't know how to use it here ! could anyone help me please?
    Kind Regards.
     
    Last edited: Jul 20, 2014
    merlin2049er likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    As this API is not exposed, you can use JavaObject to access it:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    Dim telMgr As JavaObject = GetContext.RunMethod("getSystemService"Array("phone"))
       
    Dim simState As Int = telMgr.RunMethod("getSimState"Null)
       
    Log(simState)
    End Sub


    Sub GetContext As JavaObject
      
    Return GetBA.GetField("context")
    End Sub

    Sub GetBA As JavaObject
      
    Dim jo As JavaObject
      
    Dim cls As String = Me
      cls = cls.SubString(
    "class ".Length)
      jo.InitializeStatic(cls)
      
    Return jo.GetFieldJO("processBA")
    End Sub
    You can see the constants values here: http://developer.android.com/reference/android/telephony/TelephonyManager.html#SIM_STATE_ABSENT
     
  3. KY Leng

    KY Leng Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

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