Android Question Information about second SIM in dual SIM phones

viljemto

Member
Licensed User
Longtime User
Hi!
I see that a lot of people are trying to access second SIM in dual SIM phones.

I have managed to extract methods from TelephonyManager class. Here are some that indications, where to get information for SIM1 and/or SIM2.

Now it would be great if somehow I was able to call this from B4A. Is this possible?

With regards, Viljem

B4X:
public static boolean android.telephony.TelephonyManager.dualGSMPhoneEnable()
public static boolean android.telephony.TelephonyManager.dualPhoneEnable()

public int android.telephony.TelephonyManager.getNetworkType()
public int android.telephony.TelephonyManager.getNetworkTypeExt(int)

public java.lang.String android.telephony.TelephonyManager.getNetworkTypeName()
public java.lang.String android.telephony.TelephonyManager.getNetworkTypeNameExt(int)

public boolean android.telephony.TelephonyManager.isNetworkRoaming()
public boolean android.telephony.TelephonyManager.isNetworkRoamingExt(int)

public java.lang.String android.telephony.TelephonyManager.getSubscriberId()
public java.lang.String android.telephony.TelephonyManager.getSubscriberId(java.lang.String)
public java.lang.String android.telephony.TelephonyManager.getSubscriberIdExt(int)

private com.android.internal.telephony.IPhoneSubInfo android.telephony.TelephonyManager.getSubscriberInfo()
private com.android.internal.telephony.IPhoneSubInfo android.telephony.TelephonyManager.getSubscriberInfoExt(int)
 

viljemto

Member
Licensed User
Longtime User
With this:
B4X:
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?> c = telephonyClass;
 
for (Method method : c.getDeclaredMethods()) {
  System.out.println(method);
  }
 
Upvote 0

viljemto

Member
Licensed User
Longtime User
Hi!

Yes, this is correct. I am working with HTC. For now, it will have to be different code, for different phones.

Do you have maybe some advice, how to call it?
 
Upvote 0

viljemto

Member
Licensed User
Longtime User
Hi! In Eclipse, this is working for me. But I could not get working code in B4A with Reflector.RunStaticMethod. I am getting "ClassNotFoundException" or "NullPointerException". Can you please help convert code to B4A?

B4X:
Dim r As Reflector
ToastMessageShow(r.RunStaticMethod("android.telephony.TelephonyManager",  "isNetworkRoamingExt", Array As Object(1), Array As String("java.lang.int") ), False)

B4X:
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());

Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID = telephonyClass.getMethod("getNetworkOperatorExt", parameter); //name of class

Object[] obParameter = new Object[1];
obParameter[0] = 0; //SIM ID 0,1...
Object ob_phone = getSimID.invoke(telephony, obParameter);

String value = ob_phone.toString();
 
Upvote 0

viljemto

Member
Licensed User
Longtime User
I was thinking of that, but it is easier for having all code in B4A for debuging, develpment at this point.
I will take a look this tool. Before I was doing libraries in Eclipse.

At this point...do you maybe have any idea, what I am doing wrong? Thank you!
 
Upvote 0
Top