貌似只有中国有双卡双待这种强大的功能,外国那是没有的。所以android的标准api并不支持双卡。使用getDeviceId只能得到一个IMEI,不能指定是哪个,插卡和没插卡也许也会不一样。
通过反射的话,可以读取双卡的信息,不过因为没有统一的解决方案,不同的厂商的解决方案会不一样。
下面是MTK平台的:
private void getSIMInfo() {
try {
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName("com.android.internal.telephony.Phone");
Field fields1 = c.getField("GEMINI_SIM_1");
fields1.setAccessible(true);
int simId_1 = (Integer) fields1.get(null);
Field fields2 = c.getField("GEMINI_SIM_2");
fields2.setAccessible(true);
int simId_2 = (Integer) fields2.get(null);
Method m = TelephonyManager.class.getDeclaredMethod(
"getSubscriberIdGemini", int.class);
String imsi_1 = (String) m.invoke(tm, simId_1);
String imsi_2 = (String) m.invoke(tm, simId_2);
Method m1 = TelephonyManager.class.getDeclaredMethod(
"getDeviceIdGemini", int.class);
String imei_1 = (String) m1.invoke(tm, simId_1);
String imei_2 = (String) m1.invoke(tm, simId_2);
Method mx = TelephonyManager.class.getDeclaredMethod(
"getPhoneTypeGemini", int.class);
int phoneType_1 = (Integer) mx.invoke(tm, simId_1);
int phoneType_2 = (Integer) mx.invoke(tm, simId_2);
} catch (Exception e) {
e.printStackTrace();
}
}
上述方法可以获得SIM卡的信息;
另一个方法:
private void getSIMInfo() {
try {
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName("com.android.internal.telephony.Phone");
Field fields1 = c.getField("GEMINI_SIM_1");
fields1.setAccessible(true);
int simId_1 = (Integer) fields1.get(null);
Field fields2 = c.getField("GEMINI_SIM_2");
fields2.setAccessible(true);
int simId_2 = (Integer) fields2.get(null);
Method mx = TelephonyManager.class.getMethod("getDefault",
int.class);
TelephonyManager tm1 = (TelephonyManager) mx.invoke(tm, simId_1);
TelephonyManager tm2 = (TelephonyManager) mx.invoke(tm, simId_2);
String imsi_1 = tm1.getSubscriberId();
String imsi_2 = tm2.getSubscriberId();
String imei_1 = tm1.getDeviceId();
String imei_2 = tm2.getDeviceId();
int phoneType_1 = tm1.getPhoneType();
int phoneType_2 = tm2.getPhoneType();
} catch (Exception e) {
e.printStackTrace();
}
}
原文地址:http://www.myexception.cn/android/1352142.html