完美解决高通mtkk双卡信息的获取
2014-09-07 10:53
197 查看
由于国内的运营商问题,双卡手机获取IMSI号问题要根据厂商API 来实现。
下面我们就来做一套完整的分析运营商获取IMSI号逻辑。
1,首先我们要判断手机的平台。
1.1,判断手机是否MTK平台
[java] view
plaincopyprint?
public static MtkDoubleInfo initMtkDoubleSim(Context mContext) {
MtkDoubleInfo mtkDoubleInfo = new MtkDoubleInfo();
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);
mtkDoubleInfo.setSimId_1((Integer) fields1.get(null));
Field fields2 = c.getField("GEMINI_SIM_2");
fields2.setAccessible(true);
mtkDoubleInfo.setSimId_2((Integer) fields2.get(null));
Method m = TelephonyManager.class.getDeclaredMethod(
"getSubscriberIdGemini", int.class);
mtkDoubleInfo.setImsi_1((String) m.invoke(tm,
mtkDoubleInfo.getSimId_1()));
mtkDoubleInfo.setImsi_2((String) m.invoke(tm,
mtkDoubleInfo.getSimId_2()));
Method m1 = TelephonyManager.class.getDeclaredMethod(
"getDeviceIdGemini", int.class);
mtkDoubleInfo.setImei_1((String) m1.invoke(tm,
mtkDoubleInfo.getSimId_1()));
mtkDoubleInfo.setImei_2((String) m1.invoke(tm,
mtkDoubleInfo.getSimId_2()));
Method mx = TelephonyManager.class.getDeclaredMethod(
"getPhoneTypeGemini", int.class);
mtkDoubleInfo.setPhoneType_1((Integer) mx.invoke(tm,
mtkDoubleInfo.getSimId_1()));
mtkDoubleInfo.setPhoneType_2((Integer) mx.invoke(tm,
mtkDoubleInfo.getSimId_2()));
if (TextUtils.isEmpty(mtkDoubleInfo.getImsi_1())
&& (!TextUtils.isEmpty(mtkDoubleInfo.getImsi_2()))) {
mtkDoubleInfo.setDefaultImsi(mtkDoubleInfo.getImsi_2());
}
if (TextUtils.isEmpty(mtkDoubleInfo.getImsi_2())
&& (!TextUtils.isEmpty(mtkDoubleInfo.getImsi_1()))) {
mtkDoubleInfo.setDefaultImsi(mtkDoubleInfo.getImsi_1());
}
} catch (Exception e) {
mtkDoubleInfo.setMtkDoubleSim(false);
return mtkDoubleInfo;
}
mtkDoubleInfo.setMtkDoubleSim(true);
return mtkDoubleInfo;
}
直接判断异常。出现异常证明就不是MTK平台了。
1.2判断手机是否高通平台
[java] view
plaincopyprint?
public static GaotongDoubleInfo initQualcommDoubleSim(Context mContext) {
GaotongDoubleInfo gaotongDoubleInfo = new GaotongDoubleInfo();
gaotongDoubleInfo.setSimId_1(0);
gaotongDoubleInfo.setSimId_2(1);
try {
Class<?> cx = Class
.forName("android.telephony.MSimTelephonyManager");
Object obj = mContext.getSystemService("phone_msim");
Method md = cx.getMethod("getDeviceId", int.class);
Method ms = cx.getMethod("getSubscriberId", int.class);
gaotongDoubleInfo.setImei_1((String) md.invoke(obj,
gaotongDoubleInfo.getSimId_1()));
gaotongDoubleInfo.setImei_2((String) md.invoke(obj,
gaotongDoubleInfo.getSimId_2()));
gaotongDoubleInfo.setImsi_1((String) ms.invoke(obj,
gaotongDoubleInfo.getSimId_1()));
gaotongDoubleInfo.setImsi_2((String) ms.invoke(obj,
gaotongDoubleInfo.getSimId_2()));
} catch (Exception e) {
e.printStackTrace();
gaotongDoubleInfo.setGaotongDoubleSim(false);
return gaotongDoubleInfo;
}
return gaotongDoubleInfo;
}
一样出现异常就不是高通双卡平台了
然后我们在整理下逻辑
[java] view
plaincopyprint?
/**
* @param c
* @return 返回平台数据
*/
public Object isDoubleSim(Context c) {
GaotongDoubleInfo gaotongDoubleInfo = MultiSimUtility
.initQualcommDoubleSim(c);
MtkDoubleInfo mtkDoubleInfo = MultiSimUtility.initMtkDoubleSim(c);
boolean isGaoTongCpu = gaotongDoubleInfo.isGaotongDoubleSim();
boolean isMtkCpu = mtkDoubleInfo.isMtkDoubleSim();
if (isGaoTongCpu) {
// 高通芯片双卡
return gaotongDoubleInfo;
} else if (isMtkCpu) {
// MTK芯片双卡
return mtkDoubleInfo;
} else {
//普通单卡手机
return null;
}
}
这个时候我们基本上获取到了手机的平台和每张卡的信息。单卡手机获取信息就不贴代码了。
下面我们就来做一套完整的分析运营商获取IMSI号逻辑。
1,首先我们要判断手机的平台。
1.1,判断手机是否MTK平台
[java] view
plaincopyprint?
public static MtkDoubleInfo initMtkDoubleSim(Context mContext) {
MtkDoubleInfo mtkDoubleInfo = new MtkDoubleInfo();
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);
mtkDoubleInfo.setSimId_1((Integer) fields1.get(null));
Field fields2 = c.getField("GEMINI_SIM_2");
fields2.setAccessible(true);
mtkDoubleInfo.setSimId_2((Integer) fields2.get(null));
Method m = TelephonyManager.class.getDeclaredMethod(
"getSubscriberIdGemini", int.class);
mtkDoubleInfo.setImsi_1((String) m.invoke(tm,
mtkDoubleInfo.getSimId_1()));
mtkDoubleInfo.setImsi_2((String) m.invoke(tm,
mtkDoubleInfo.getSimId_2()));
Method m1 = TelephonyManager.class.getDeclaredMethod(
"getDeviceIdGemini", int.class);
mtkDoubleInfo.setImei_1((String) m1.invoke(tm,
mtkDoubleInfo.getSimId_1()));
mtkDoubleInfo.setImei_2((String) m1.invoke(tm,
mtkDoubleInfo.getSimId_2()));
Method mx = TelephonyManager.class.getDeclaredMethod(
"getPhoneTypeGemini", int.class);
mtkDoubleInfo.setPhoneType_1((Integer) mx.invoke(tm,
mtkDoubleInfo.getSimId_1()));
mtkDoubleInfo.setPhoneType_2((Integer) mx.invoke(tm,
mtkDoubleInfo.getSimId_2()));
if (TextUtils.isEmpty(mtkDoubleInfo.getImsi_1())
&& (!TextUtils.isEmpty(mtkDoubleInfo.getImsi_2()))) {
mtkDoubleInfo.setDefaultImsi(mtkDoubleInfo.getImsi_2());
}
if (TextUtils.isEmpty(mtkDoubleInfo.getImsi_2())
&& (!TextUtils.isEmpty(mtkDoubleInfo.getImsi_1()))) {
mtkDoubleInfo.setDefaultImsi(mtkDoubleInfo.getImsi_1());
}
} catch (Exception e) {
mtkDoubleInfo.setMtkDoubleSim(false);
return mtkDoubleInfo;
}
mtkDoubleInfo.setMtkDoubleSim(true);
return mtkDoubleInfo;
}
直接判断异常。出现异常证明就不是MTK平台了。
1.2判断手机是否高通平台
[java] view
plaincopyprint?
public static GaotongDoubleInfo initQualcommDoubleSim(Context mContext) {
GaotongDoubleInfo gaotongDoubleInfo = new GaotongDoubleInfo();
gaotongDoubleInfo.setSimId_1(0);
gaotongDoubleInfo.setSimId_2(1);
try {
Class<?> cx = Class
.forName("android.telephony.MSimTelephonyManager");
Object obj = mContext.getSystemService("phone_msim");
Method md = cx.getMethod("getDeviceId", int.class);
Method ms = cx.getMethod("getSubscriberId", int.class);
gaotongDoubleInfo.setImei_1((String) md.invoke(obj,
gaotongDoubleInfo.getSimId_1()));
gaotongDoubleInfo.setImei_2((String) md.invoke(obj,
gaotongDoubleInfo.getSimId_2()));
gaotongDoubleInfo.setImsi_1((String) ms.invoke(obj,
gaotongDoubleInfo.getSimId_1()));
gaotongDoubleInfo.setImsi_2((String) ms.invoke(obj,
gaotongDoubleInfo.getSimId_2()));
} catch (Exception e) {
e.printStackTrace();
gaotongDoubleInfo.setGaotongDoubleSim(false);
return gaotongDoubleInfo;
}
return gaotongDoubleInfo;
}
一样出现异常就不是高通双卡平台了
然后我们在整理下逻辑
[java] view
plaincopyprint?
/**
* @param c
* @return 返回平台数据
*/
public Object isDoubleSim(Context c) {
GaotongDoubleInfo gaotongDoubleInfo = MultiSimUtility
.initQualcommDoubleSim(c);
MtkDoubleInfo mtkDoubleInfo = MultiSimUtility.initMtkDoubleSim(c);
boolean isGaoTongCpu = gaotongDoubleInfo.isGaotongDoubleSim();
boolean isMtkCpu = mtkDoubleInfo.isMtkDoubleSim();
if (isGaoTongCpu) {
// 高通芯片双卡
return gaotongDoubleInfo;
} else if (isMtkCpu) {
// MTK芯片双卡
return mtkDoubleInfo;
} else {
//普通单卡手机
return null;
}
}
这个时候我们基本上获取到了手机的平台和每张卡的信息。单卡手机获取信息就不贴代码了。
相关文章推荐
- Android 获取运营商信息(完整版)-解决高通,MTK等双卡问题
- Android 获取运营商信息(完整版)-解决高通,MTK等双卡问题
- Android 获取运营商信息(完整版)-解决高通,MTK等双卡问题
- filezilla ftp client在win7 下获取ftp目录信息出错解决方法
- Win8 Metro应用 分享一直显示 “正在从xxx应用获取信息” 的解决办法
- SystemParametersInfo获取信息失败问题的解决
- 解决获取到的网页信息 中文乱码
- suse10中安装的oracle10后,sqlplus中的提示信息全部是??号的完美解决方法
- 获取本机地址信息,遇到小问题...有待解决
- 解决 CAS + Spring Security整合 无法获取当前登录用户信息
- vb.net用API函数getWindowRect()获取窗体位置信息失败解决
- 获取PHP警告错误信息的解决方法
- 读取配置参数的properties文件,路径获取完美解决
- DBF操作:多线程下的ADO连接DBF文件获取信息的解决
- 当遇到Context [/TSORM] startup failed due to previous errors时,解决办法:配置tomcat的日志获取错误信息
- 解决 CAS + Spring Security整合 无法获取当前登录用户信息
- OC从Exchange服务器上获取日历和外出信息的错误解决办法
- 各类Java heap space 解决方法,并通过java代码获取JVM的相关信息,所在操作系统的信息(包含eclipse&amp;myeclipse的调试的内存设置)
- statfs函数获取大容量磁盘信息速度慢的解决过程
- 关于android各种双卡手机获取imei,imsi的处置(mtk,展讯,高通等)