關於android各類雙卡手機獲取imei,imsi的處置(mtk,展訊,高通等)

關於android各類雙卡手機獲取imei,imsi的處理(mtk,展訊,高通等)

目前國內對於雙卡智能手機的需求仍是很大的,各類複雜的業務會涉及到雙卡模塊;而android標準的api又不提供對雙卡的支持。致使國內雙卡模塊標準混亂,各個廠商各玩各的。目前我知道的雙卡解決方案就有:mtk,展訊,高通,broadcom等 java

 

首先是最爲應用普遍的mtk平臺,國內山寨手機以及一些低端品牌雙卡都是作的mtk的雙卡解決方案 android

 

 

private static void initMtkDoubleSim() {
		try {
			TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
			Class<?> c = Class.forName("com.android.internal.telephony.Phone");
			Field fields1 = c.getField("GEMINI_SIM_1");
			fields1.setAccessible(true);
			simId_1 = (Integer) fields1.get(null);
			Field fields2 = c.getField("GEMINI_SIM_2");
			fields2.setAccessible(true);
			simId_2 = (Integer) fields2.get(null);

			Method m = TelephonyManager.class.getDeclaredMethod(
					"getSubscriberIdGemini", int.class);
			imsi_1 = (String) m.invoke(tm, simId_1);
			imsi_2 = (String) m.invoke(tm, simId_2);

			Method m1 = TelephonyManager.class.getDeclaredMethod(
					"getDeviceIdGemini", int.class);
			imei_1 = (String) m1.invoke(tm, simId_1);
			imei_2 = (String) m1.invoke(tm, simId_2);

			Method mx = TelephonyManager.class.getDeclaredMethod(
					"getPhoneTypeGemini", int.class);
			phoneType_1 = (Integer) mx.invoke(tm, simId_1);
			phoneType_2 = (Integer) mx.invoke(tm, simId_2);

			if (TextUtils.isEmpty(imsi_1) && (!TextUtils.isEmpty(imsi_2))) {
				defaultImsi = imsi_2;
			}
			if (TextUtils.isEmpty(imsi_2) && (!TextUtils.isEmpty(imsi_1))) {
				defaultImsi = imsi_1;
			}
		} catch (Exception e) {
			isMtkDoubleSim = false;
			return;
		}
		isMtkDoubleSim = true;
	}

 

 

 可見,在TelephonyManager中提供了**Gemini的方法,能夠用反射很方便地獲取到相應的信息。 api

 

還有 spa

private static void initMtkSecondDoubleSim() {
		try {
			TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
			Class<?> c = Class.forName("com.android.internal.telephony.Phone");
			Field fields1 = c.getField("GEMINI_SIM_1");
			fields1.setAccessible(true);
			simId_1 = (Integer) fields1.get(null);
			Field fields2 = c.getField("GEMINI_SIM_2");
			fields2.setAccessible(true);
			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);

			imsi_1 = tm1.getSubscriberId();
			imsi_2 = tm2.getSubscriberId();

			imei_1 = tm1.getDeviceId();
			imei_2 = tm2.getDeviceId();

			phoneType_1 = tm1.getPhoneType();
			phoneType_2 = tm2.getPhoneType();

			if (TextUtils.isEmpty(imsi_1) && (!TextUtils.isEmpty(imsi_2))) {
				defaultImsi = imsi_2;
			}
			if (TextUtils.isEmpty(imsi_2) && (!TextUtils.isEmpty(imsi_1))) {
				defaultImsi = imsi_1;
			}

		} catch (Exception e) {
			isMtkSecondDoubleSim = false;
			return;
		}
		isMtkSecondDoubleSim = true;
	}

 

 看樣子有彷佛也是屬於mtk平臺的解決方案,由於都有GEMINI_SIM_1屬性,這種雙卡方案只在聯想278t上發現過;有兩個TelephonyManager實例,根據getDefault方法獲取 code

下面是展訊平臺的(貌似市面上手機很少啊): 接口

private static void initSpreadDoubleSim() {
		try {
			Class<?> c = Class
					.forName("com.android.internal.telephony.PhoneFactory");
			Method m = c.getMethod("getServiceName", String.class, int.class);
			spreadTmService = (String) m
					.invoke(c, Context.TELEPHONY_SERVICE, 1);

			TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
			imsi_1 = tm.getSubscriberId();
			imei_1 = tm.getDeviceId();
			phoneType_1 = tm.getPhoneType();
			TelephonyManager tm1 = (TelephonyManager) mContext.getSystemService(spreadTmService);
			imsi_2 = tm1.getSubscriberId();
			imei_2 = tm1.getDeviceId();
			phoneType_2 = tm1.getPhoneType();
			if (TextUtils.isEmpty(imsi_1) && (!TextUtils.isEmpty(imsi_2))) {
				defaultImsi = imsi_2;
			}
			if (TextUtils.isEmpty(imsi_2) && (!TextUtils.isEmpty(imsi_1))) {
				defaultImsi = imsi_1;
			}

		} catch (Exception e) {
			isSpreadDoubleSim = false;
			return;
		}
		isSpreadDoubleSim = true;
	}

 

 這個沒有展訊sdk的話仍是很難找的吧? get

下面是高通的:(貌似高通作的不咋的有些接口沒有雙卡實現啊) it

public static void initQualcommDoubleSim() {
try {
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> cx = Class
.forName("android.telephony.MSimTelephonyManager");
Object obj =mContext.getSystemService(
"phone_msim");
simId_1 = 0;
simId_2 = 1;
 
Method mx = cx.getMethod("getDataState");
// int stateimei_1 = (Integer) mx.invoke(cx.newInstance());
int stateimei_2 = tm.getDataState();
Method mde = cx.getMethod("getDefault");
Method md = cx.getMethod("getDeviceId", int.class);
Method ms = cx.getMethod("getSubscriberId", int.class);
Method mp = cx.getMethod("getPhoneType");
 
// Object obj = mde.invoke(cx);
 
imei_1 = (String) md.invoke(obj, simId_1);
imei_2 = (String) md.invoke(obj, simId_2);
 
imsi_1 = (String) ms.invoke(obj, simId_1);
imsi_2 = (String) ms.invoke(obj, simId_2);
 
int statephoneType_1 = tm.getDataState();
int statephoneType_2 = (Integer) mx.invoke(obj);
Log.e("tag", statephoneType_1 + "---" + statephoneType_2);
 
// Class<?> msc = Class.forName("android.telephony.MSimSmsManager");
// for (Method m : msc.getMethods()) {
// if (m.getName().equals("sendTextMessage")) {
// m.getParameterTypes();
// }
// Log.e("tag", m.getName());
// }
 
} catch (Exception e) {
isQualcommDoubleSim = false;
return;
}
isQualcommDoubleSim = true;
 
}

 

getPhoneType&getDataState 方法看了底層發現沒有雙卡實現,目前也不知道該咋辦... io

相關文章
相關標籤/搜索