/**
* 获取双卡手机的两个卡的IMSI 需要 READ_PHONE_STATE 权限
*
* @param context
* 上下文
* @return 下标0为一卡的IMSI,下标1为二卡的IMSI
*/
public static String[] getIMSI(Context context) {
// 双卡imsi的数组
String[] imsis = new String[2];
try {
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
// 先使用默认的获取方式获取一卡IMSI
imsis[0] = tm.getSubscriberId();
// 然后进行二卡IMSI的获取,默认先获取展讯的IMSI
try {
Method method = tm.getClass().getDeclaredMethod(
"getSubscriberIdGemini", int.class);
method.setAccessible(true);
// 0 表示 一卡,1 表示二卡,下方获取相同
imsis[1] = (String) method.invoke(tm, 1);
} catch (Exception e) {
// 异常清空数据,继续获取下一个
imsis[1] = null;
}
if (imsis[1] == null || "".equals(imsis[1])) { // 如果二卡为空就获取mtk
try {
Class<?> c = Class
.forName("com.android.internal.telephony.PhoneFactory");
Method m = c.getMethod("getServiceName", String.class,
int.class);
String spreadTmService = (String) m.invoke(c,
Context.TELEPHONY_SERVICE, 1);
TelephonyManager tm1 = (TelephonyManager) context
.getSystemService(spreadTmService);
imsis[1] = tm1.getSubscriberId();
} catch (Exception ex) {
imsis[1] = null;
}
}
if (imsis[1] == null || "".equals(imsis[1])) { // 如果二卡为空就获取高通 IMSI获取
try {
Method addMethod2 = tm.getClass().getDeclaredMethod(
"getSimSerialNumber", int.class);
addMethod2.setAccessible(true);
imsis[1] = (String) addMethod2.invoke(tm, 1);
} catch (Exception ex) {
imsis[1] = null;
}
}
} catch (IllegalArgumentException e) {
}
return imsis;
}
}