Android obtains carrier information (full version)-solves dual-card problems such as Qualcomm and MTK

Source: Internet
Author: User

Due to carrier problems in China, the problem of getting IMSI numbers from dual-card mobile phones should be implemented according to the manufacturer's API.

Next we will do a complete set of analysis operators to obtain the IMSI logic.

1. First, we need to determine the mobile phone platform.

1.1. Determine whether the mobile phone is MTK Platform

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;}
Identify exceptions directly. If an exception occurs, the MTK platform is not used.

1.2 determine whether the mobile phone is a Qualcomm Platform

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;}
If an exception occurs, it is not the Qualcomm dual-card platform.

Then we sorted out the logic.

/*** @ Param c * @ return returns Platform Data */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) {// Qualcomm chip dual-card return gaotongDoubleInfo;} else if (isMtkCpu) {// MTK chip dual-card return mtkDoubleInfo ;} else {// normal single-card mobile phone return null ;}}

At this time, we basically got information about the mobile phone platform and each card. A single-card mobile phone will not post code for obtaining information.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.