博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于android各种双卡手机获取imei,imsi的处理(mtk,展讯,高通等)
阅读量:4705 次
发布时间:2019-06-10

本文共 5229 字,大约阅读时间需要 17 分钟。

目前国内对于双卡智能手机的需求还是很大的,各种复杂的业务会涉及到双卡模块;而android标准的api又不提供对双卡的支持。导致国内双卡模块标准混乱,各个厂商各玩各的。目前我知道的双卡解决方案就有:mtk,展讯,高通,broadcom等。

 

由于公司业务需要,必须要对双卡手机获取各自的imei,imsi,所以也做了一些研究:

 

首先是最为应用广泛的mtk平台,国内山寨手机以及一些低端品牌双卡都是做的mtk的双卡解决方案

 

 

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的方法,可以用反射很方便地获取到相应的信息。

 

还有

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方法获取

下面是展讯平台的(貌似市面上手机不多啊):

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的话还是很难找的吧?

下面是高通的:(貌似高通做的不咋的有些接口没有双卡实现啊)

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 方法看了底层发现没有双卡实现,目前也不知道该咋办...

 

转载于:https://www.cnblogs.com/Free-Thinker/p/3668296.html

你可能感兴趣的文章
不把DB放进容器的理由
查看>>
OnePage收集
查看>>
Java parseInt()方法
查看>>
yahoo的30条优化规则
查看>>
[CCF2015.09]题解
查看>>
[NYIST15]括号匹配(二)(区间dp)
查看>>
json_value.cpp : fatal error C1083: 无法打开编译器生成的文件:No such file or directory
查看>>
洛谷 P1101 单词方阵
查看>>
Swift DispatchQueue
查看>>
C#和JAVA 访问修饰符
查看>>
小甲鱼OD学习第1讲
查看>>
HDU-1085 Holding Bin-Laden Captive-母函数
查看>>
php提示undefined index的几种解决方法
查看>>
LRJ
查看>>
Struts2环境搭建
查看>>
Linux: Check version info
查看>>
stl学习之测试stlen,cout等的运行速度
查看>>
魔戒三曲,黑暗散去;人皇加冕,光明归来
查看>>
Error和Exception
查看>>
Python和Singleton (单件)模式[转载]
查看>>