/**
* Create a Telephonyinfo.java class
*/
Import Java.lang.reflect.Method;
Import Android.content.Context;
Import Android.telephony.TelephonyManager;
Public final class Telephonyinfo {
private static Telephonyinfo Telephonyinfo;
Private String imeiSIM1;
Private String imeiSIM2;
Private Boolean Issim1ready;
Private Boolean Issim2ready;
Public String getImeiSIM1 () {
return imeiSIM1;
}
/*public static void SetImeiSIM1 (String imeiSIM1) {
TELEPHONYINFO.IMEISIM1 = imeiSIM1;
}*/
Public String getImeiSIM2 () {
return imeiSIM2;
}
/*public static void SetImeiSIM2 (String imeiSIM2) {
TELEPHONYINFO.IMEISIM2 = imeiSIM2;
}*/
public Boolean Issim1ready () {
return issim1ready;
}
/*public static void Setsim1ready (Boolean issim1ready) {
Telephonyinfo.issim1ready = Issim1ready;
}*/
public Boolean Issim2ready () {
return issim2ready;
}
/*public static void Setsim2ready (Boolean issim2ready) {
Telephonyinfo.issim2ready = Issim2ready;
}*/
public Boolean Isdualsim () {
return imeiSIM2! = NULL;
}
Private Telephonyinfo () {
}
public static Telephonyinfo getinstance (context context) {
if (Telephonyinfo = = null) {
Telephonyinfo = new Telephonyinfo ();
Telephonymanager Telephonymanager = ((Telephonymanager) Context.getsystemservice (Context.telephony_service));
TELEPHONYINFO.IMEISIM1 = Telephonymanager.getdeviceid ();
TELEPHONYINFO.IMEISIM2 = null;
try {
TELEPHONYINFO.IMEISIM1 = Getdeviceidbyslot (Context, "Getdeviceidgemini", 0);
TELEPHONYINFO.IMEISIM2 = Getdeviceidbyslot (Context, "Getdeviceidgemini", 1);
} catch (Geminimethodnotfoundexception e) {
E.printstacktrace ();
try {
TELEPHONYINFO.IMEISIM1 = Getdeviceidbyslot (Context, "Getdeviceid", 0);
TELEPHONYINFO.IMEISIM2 = Getdeviceidbyslot (Context, "Getdeviceid", 1);
} catch (Geminimethodnotfoundexception E1) {
Call here for next manufacturer's predicted method name if you wish
E1.printstacktrace ();
}
}
Telephonyinfo.issim1ready = telephonymanager.getsimstate () = = Telephonymanager.sim_state_ready;
Telephonyinfo.issim2ready = false;
try {
Telephonyinfo.issim1ready = Getsimstatebyslot (Context, "Getsimstategemini", 0);
Telephonyinfo.issim2ready = Getsimstatebyslot (Context, "Getsimstategemini", 1);
} catch (Geminimethodnotfoundexception e) {
E.printstacktrace ();
try {
Telephonyinfo.issim1ready = Getsimstatebyslot (Context, "Getsimstate", 0);
Telephonyinfo.issim2ready = Getsimstatebyslot (Context, "getsimstate", 1);
} catch (Geminimethodnotfoundexception E1) {
Call here for next manufacturer's predicted method name if you wish
E1.printstacktrace ();
}
}
}
return telephonyinfo;
}
private static string Getdeviceidbyslot (context context, string predictedmethodname, int slotid) throws geminimethodnotfoundexception {
String IMEI = null;
Telephonymanager telephony = (Telephonymanager) context.getsystemservice (Context.telephony_service);
try{
class<?> Telephonyclass = Class.forName (Telephony.getclass (). GetName ());
class<?>[] parameter = new CLASS[1];
Parameter[0] = Int.class;
Method Getsimid = Telephonyclass.getmethod (predictedmethodname, parameter);
object[] Obparameter = new Object[1];
Obparameter[0] = SlotID;
Object Ob_phone = Getsimid.invoke (telephony, obparameter);
if (ob_phone! = null) {
IMEI = Ob_phone.tostring ();
}
} catch (Exception e) {
E.printstacktrace ();
throw new Geminimethodnotfoundexception (Predictedmethodname);
}
return IMEI;
}
private static Boolean Getsimstatebyslot (context context, String predictedmethodname, int slotid) throws geminimethodnotfoundexception {
Boolean isReady = false;
Telephonymanager telephony = (Telephonymanager) context.getsystemservice (Context.telephony_service);
try{
class<?> Telephonyclass = Class.forName (Telephony.getclass (). GetName ());
class<?>[] parameter = new CLASS[1];
Parameter[0] = Int.class;
Method Getsimstategemini = Telephonyclass.getmethod (predictedmethodname, parameter);
object[] Obparameter = new Object[1];
Obparameter[0] = SlotID;
Object Ob_phone = Getsimstategemini.invoke (telephony, obparameter);
if (ob_phone! = null) {
int simstate = Integer.parseint (ob_phone.tostring ());
if (simstate = = Telephonymanager.sim_state_ready) {
IsReady = true;
}
}
} catch (Exception e) {
E.printstacktrace ();
throw new Geminimethodnotfoundexception (Predictedmethodname);
}
return isReady;
}
private static class Geminimethodnotfoundexception extends Exception {
Private static final long serialversionuid = -996812356902545308l;
Public geminimethodnotfoundexception (String info) {
Super (info);
}
}
}
And then use the This class as that:
Private voidIsdualsimornot(){ TelephonyinfoTelephonyinfo= Telephonyinfo.GetInstance(This); StringImeiSIM1=Telephonyinfo.GetImeiSIM1(); StringImeiSIM2=Telephonyinfo.GetImeiSIM2(); BooleanIssim1ready=Telephonyinfo.Issim1ready(); BooleanIssim2ready=Telephonyinfo.Issim2ready(); BooleanIsdualsim=Telephonyinfo.Isdualsim(); Log.I("Dual =","IME1:" +ImeiSIM1+ "\ n" + "IME2:" +ImeiSIM2+ "\ n" + "is DUAL SIM:" Span class= "PLN" > + Isdualsim + + "is SIM1 ready:" + Issim1ready + " \ N " + " is SIM2 ready: " Span class= "pun" >+ Issim2ready + "\ n" } /span>
Above code works perfectly for me.
Reprinted from: Http://stackoverflow.com/questions/11880881/how-can-i-get-both-imei-numbers-from-dual-sim-mobile
Android dual phone to get IMEI for each SIM card