由于国内的运营商问题,双卡手机获取IMSI号问题要根据厂商API 来实现。

下面我们就来做一套完整的分析运营商获取IMSI号逻辑。

1,首先我们要判断手机的平台。

    1.1,判断手机是否MTK平台

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判断手机是否高通平台

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;}
一样出现异常就不是高通双卡平台了

然后我们在整理下逻辑

/** * @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;}}

这个时候我们基本上获取到了手机的平台和每张卡的信息。单卡手机获取信息就不贴代码了。



更多相关文章

  1. 获取Android设备的唯一识别码UUID
  2. Android(安卓)平台未安装邮件客户端,点击邮件链接,程序崩溃问题
  3. Android升级apk签名文件校验
  4. Android注册设备管理器(获取超级管理员权限)
  5. Android中Java根据文件头获取文件类型
  6. android用SharedPreferences保存登录账户密码
  7. android调用系统相机拍照保存照片并显示在当前界面
  8. andoridStudio详细配置
  9. 引用JNI版本----MediaMetadataRetriever获取视频缩略图(真机4.0测

随机推荐

  1. Android(安卓)Design Support Library(二)
  2. Application、Activity Stack 和 Task的
  3. Android:Gravity控制格式
  4. 关于progressbar进度条的显示风格及一些
  5. 源码解析Android中AsyncTask的工作原理
  6. 【Android开发】背景选择器selector用法
  7. 阅读手札:《:第一行代码》(第一章)
  8. 基于Android FrameLayout的使用详解
  9. 使用ProgressBar实现加载进度条
  10. Android的安全体系