Android 解决双卡双待的问题

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

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

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

    1.1,判断手机是否MTK平台

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. public static MtkDoubleInfo initMtkDoubleSim(Context mContext) {  
  2.     MtkDoubleInfo mtkDoubleInfo = new MtkDoubleInfo();  
  3.     try {  
  4.         TelephonyManager tm = (TelephonyManager) mContext  
  5.                 .getSystemService(Context.TELEPHONY_SERVICE);  
  6.         Class<?> c = Class.forName("com.android.internal.telephony.Phone");  
  7.         Field fields1 = c.getField("GEMINI_SIM_1");  
  8.         fields1.setAccessible(true);  
  9.         mtkDoubleInfo.setSimId_1((Integer) fields1.get(null));  
  10.         Field fields2 = c.getField("GEMINI_SIM_2");  
  11.         fields2.setAccessible(true);  
  12.         mtkDoubleInfo.setSimId_2((Integer) fields2.get(null));  
  13.         Method m = TelephonyManager.class.getDeclaredMethod(  
  14.                 "getSubscriberIdGemini"int.class);  
  15.         mtkDoubleInfo.setImsi_1((String) m.invoke(tm,  
  16.                 mtkDoubleInfo.getSimId_1()));  
  17.         mtkDoubleInfo.setImsi_2((String) m.invoke(tm,  
  18.                 mtkDoubleInfo.getSimId_2()));  
  19.   
  20.         Method m1 = TelephonyManager.class.getDeclaredMethod(  
  21.                 "getDeviceIdGemini"int.class);  
  22.         mtkDoubleInfo.setImei_1((String) m1.invoke(tm,  
  23.                 mtkDoubleInfo.getSimId_1()));  
  24.         mtkDoubleInfo.setImei_2((String) m1.invoke(tm,  
  25.                 mtkDoubleInfo.getSimId_2()));  
  26.   
  27.         Method mx = TelephonyManager.class.getDeclaredMethod(  
  28.                 "getPhoneTypeGemini"int.class);  
  29.         mtkDoubleInfo.setPhoneType_1((Integer) mx.invoke(tm,  
  30.                 mtkDoubleInfo.getSimId_1()));  
  31.         mtkDoubleInfo.setPhoneType_2((Integer) mx.invoke(tm,  
  32.                 mtkDoubleInfo.getSimId_2()));  
  33.   
  34.         if (TextUtils.isEmpty(mtkDoubleInfo.getImsi_1())  
  35.                 && (!TextUtils.isEmpty(mtkDoubleInfo.getImsi_2()))) {  
  36.             mtkDoubleInfo.setDefaultImsi(mtkDoubleInfo.getImsi_2());  
  37.         }  
  38.         if (TextUtils.isEmpty(mtkDoubleInfo.getImsi_2())  
  39.                 && (!TextUtils.isEmpty(mtkDoubleInfo.getImsi_1()))) {  
  40.             mtkDoubleInfo.setDefaultImsi(mtkDoubleInfo.getImsi_1());  
  41.         }  
  42.     } catch (Exception e) {  
  43.         mtkDoubleInfo.setMtkDoubleSim(false);  
  44.         return mtkDoubleInfo;  
  45.     }  
  46.     mtkDoubleInfo.setMtkDoubleSim(true);  
  47.     return mtkDoubleInfo;  
  48. }  
直接判断异常。出现异常证明就不是MTK平台了。

1.2判断手机是否高通平台

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. public static GaotongDoubleInfo initQualcommDoubleSim(Context mContext) {  
  2.         GaotongDoubleInfo gaotongDoubleInfo = new GaotongDoubleInfo();  
  3.         gaotongDoubleInfo.setSimId_1(0);  
  4.         gaotongDoubleInfo.setSimId_2(1);  
  5.         try {  
  6.             Class<?> cx = Class  
  7.                     .forName("android.telephony.MSimTelephonyManager");  
  8.             Object obj = mContext.getSystemService("phone_msim");  
  9.   
  10.             Method md = cx.getMethod("getDeviceId"int.class);  
  11.             Method ms = cx.getMethod("getSubscriberId"int.class);  
  12.   
  13.             gaotongDoubleInfo.setImei_1((String) md.invoke(obj,  
  14.                     gaotongDoubleInfo.getSimId_1()));  
  15.             gaotongDoubleInfo.setImei_2((String) md.invoke(obj,  
  16.                     gaotongDoubleInfo.getSimId_2()));  
  17.             gaotongDoubleInfo.setImsi_1((String) ms.invoke(obj,  
  18.                     gaotongDoubleInfo.getSimId_1()));  
  19.             gaotongDoubleInfo.setImsi_2((String) ms.invoke(obj,  
  20.                     gaotongDoubleInfo.getSimId_2()));  
  21.         } catch (Exception e) {  
  22.             e.printStackTrace();  
  23.             gaotongDoubleInfo.setGaotongDoubleSim(false);  
  24.             return gaotongDoubleInfo;  
  25.         }  
  26.         return gaotongDoubleInfo;  
  27.     }  
一样出现异常就不是高通双卡平台了

然后我们在整理下逻辑

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. /** 
  2.  * @param c 
  3.  * @return 返回平台数据 
  4.  */  
  5. public Object isDoubleSim(Context c) {  
  6.     GaotongDoubleInfo gaotongDoubleInfo = MultiSimUtility  
  7.             .initQualcommDoubleSim(c);  
  8.     MtkDoubleInfo mtkDoubleInfo = MultiSimUtility.initMtkDoubleSim(c);  
  9.     boolean isGaoTongCpu = gaotongDoubleInfo.isGaotongDoubleSim();  
  10.     boolean isMtkCpu = mtkDoubleInfo.isMtkDoubleSim();  
  11.     if (isGaoTongCpu) {  
  12.         // 高通芯片双卡  
  13.         return gaotongDoubleInfo;  
  14.     } else if (isMtkCpu) {  
  15.         // MTK芯片双卡  
  16.         return mtkDoubleInfo;  
  17.     } else {  
  18.         //普通单卡手机  
  19.         return null;  
  20.     }  
  21. }  

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值