辅助SIM卡的MNC和MCC

时间:2016-02-17 06:08:04

标签: android telephonymanager

我知道使用TelephonyManager我们可以获得我们网络提供商的MNC和MCC,

TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = tel.getNetworkOperator();

if (networkOperator != null) {
    int mcc = Integer.parseInt(networkOperator.substring(0, 3));
    int mnc = Integer.parseInt(networkOperator.substring(3));
}

但我能够获得只有主要SIM卡的MNC和MCC数据。我想知道有没有办法在android中获取设备的辅助sim卡的mnc,mcc,lac和cellid。

3 个答案:

答案 0 :(得分:2)

在API 22之前,很难达到你想要的效果。

我相信在API 22之前,Android最初不支持双SIM卡。因此,每个移动供应商都应该有自己的实现。也许,你应该获得他们的API / SDK并将它们包含在你的项目中。只有这样,您才能访问他们的API。

从API22开始,我认为您可以使用SubscriptionManager

    int mccSlot1 = -1;
    int mccSlot2 = -1;
    int mncSlot1 = -1;
    int mncSlot2 = -1;

    SubscriptionManager subManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

    if(subManager.getActiveSubscriptionInfoCount() >= 1) {
        mccSlot1 = subManager.getActiveSubscriptionInfo(0).getMcc();
        mncSlot1 = subManager.getActiveSubscriptionInfo(0).getMnc();
    }

    if(subManager.getActiveSubscriptionInfoCount() >= 2) {
        mccSlot2 = subManager.getActiveSubscriptionInfo(1).getMcc();
        mncSlot2 = subManager.getActiveSubscriptionInfo(1).getMnc();
    }

问题https://stackoverflow.com/a/32871156/4860513提及相同的Android限制。所以,我真的相信在使用纯Android SDK的API22之前不可能实现这一点。

答案 1 :(得分:1)

        SubscriptionManager subManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        List<SubscriptionInfo> subscriptionInfoList=new ArrayList<>();
        subscriptionInfoList=subManager.getActiveSubscriptionInfoList();
        Log.d("LIST LIST",subscriptionInfoList.toString());

日志是

[{id=4, iccId=89918610400110260628 simSlotIndex=0 displayName=Jio 4G carrierName=Jio 4G nameSource=0 iconTint=-16746133 dataRoaming=0 iconBitmap=android.graphics.Bitmap@2758949 mcc 405 mnc 861 SimProvisioningStatus 0 status 1}, {id=1, iccId=8991000900229271344 simSlotIndex=1 displayName=airtel carrierName=airtel nameSource=2 iconTint=-16746133 dataRoaming=0 iconBitmap=android.graphics.Bitmap@355e24e mcc 404 mnc 45 SimProvisioningStatus 0 status 1}]

答案 2 :(得分:1)

SubscriptionManager subManager =(SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
            == PackageManager.PERMISSION_GRANTED) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            if (subManager.getActiveSubscriptionInfoCount() >= 1) {
                List<SubscriptionInfo> subscriptionInfoList;
                subscriptionInfoList=subManager.getActiveSubscriptionInfoList();
                mccSlot1 = subscriptionInfoList.get(0).getMcc();
                mncSlot1 = subscriptionInfoList.get(0).getMnc();
                Toast.makeText(this, "Sim slot 1 " + mccSlot1 + " " + mncSlot1, Toast.LENGTH_SHORT).show();
                mccSlot2 = subscriptionInfoList.get(1).getMcc();
                mncSlot2 = subscriptionInfoList.get(1).getMnc();
                Toast.makeText(this, "Sim slot 1 " + mccSlot2 + " " + mncSlot2, Toast.LENGTH_SHORT).show();

            }
        } else {
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            if (telephonyManager == null) {
                return;
            }
            String mCCMncCode = telephonyManager.getNetworkOperator();
            String mccCode = null;
            String mncCode = null;
            if (TextUtils.isEmpty(mCCMncCode)) {
                return;
            }

            final int MNC_CODE_LENGTH = 3;
            if (mCCMncCode.length() >= MNC_CODE_LENGTH) {
                mccCode = mCCMncCode.substring(0, MNC_CODE_LENGTH);
            }

            if (mCCMncCode.length() > MNC_CODE_LENGTH) {
                mncCode = mCCMncCode.substring(MNC_CODE_LENGTH);
            }
            Toast.makeText(this, "Lower than API 22 " + mccCode + " " + mncCode, Toast.LENGTH_SHORT).show();
            return;
        }
    }
    else {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, 1);
    }