Mtelephonymanager = (Telephonymanager) context.getsystemservice (context.telephony_service);
if (Mtelephonymanager = = null) {
throw new Error ("telephony manager is null");
}
Msubscriptionmanager = Subscriptionmanager.from (Mcontext);
For a chestnut, get Subscriptionmanagergetsubid (SlotID) and Telephonymanager's getsimserialnumber (int subId)
private static int[] getsubid (int slotid) {Method declaredmethod;
int[] Subarr = null; try {Declaredmethod = Class.forName ("Android.telephony.SubscriptionManager"). Getdeclaredmethod ("Getsubid", NE
W Class[]{integer.type});
Declaredmethod.setaccessible (TRUE);
Subarr = (int[]) Declaredmethod.invoke (Msubscriptionmanager, SlotID);
} catch (ClassNotFoundException e) {e.printstacktrace ();
Declaredmethod = null;
} catch (IllegalArgumentException E2) {e2.printstacktrace ();
Declaredmethod = null;
} catch (Nosuchmethodexception E3) {e3.printstacktrace ();
Declaredmethod = null;
} catch (ClassCastException e4) {e4.printstacktrace ();
Declaredmethod = null;
} catch (Illegalaccessexception e5) {e5.printstacktrace ();
Declaredmethod = null; } catch (InvocationtargetexcEption e6) {e6.printstacktrace ();
Declaredmethod = null;
} if (Declaredmethod = = null) {Subarr = null;
} mlog.d ("getsubid =" + subarr[0]);
return Subarr;
} private String Getsimserialnumber (int subId) {method method;
String status = NULL;
try {method = Mtelephonymanager.getclass (). GetMethod ("Getsimserialnumber", Int.class);
Method.setaccessible (TRUE);
Status = String.valueof (Method.invoke (Mtelephonymanager, subId));
} catch (Nosuchmethodexception e) {e.printstacktrace ();
} catch (Illegalaccessexception e) {e.printstacktrace ();
} catch (IllegalArgumentException e) {e.printstacktrace ();
} catch (InvocationTargetException e) {e.printstacktrace ();
} mlog.d ("Getsimserialnumber =" + status);
return status; }