中國強大的雙卡雙待手機讀取IMEI號

NO IMAGE

貌似只有中國有雙卡雙待這種強大的功能,外國那是沒有的。所以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