Android Question Using TelephonyManager class

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:



B4X:
...
....
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:

Erel

Administrator
Staff member
Licensed User
As this API is not exposed, you can use JavaObject to access it:
B4X:
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
 
Top