Android : Check whether the phone is dual SIM

前端 未结 8 1957
轻奢々
轻奢々 2020-11-22 01:38

After a lot of research on forums, now I know that there is no way to find IMSI or SIM serial number for both the SIM cards in a dual SIM phone (except for contacting the ma

8条回答
  •  盖世英雄少女心
    2020-11-22 01:44

    There are several native solutions I've found while searching the way to check network operator.

    For API >=17:

    TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    
    // Get information about all radio modules on device board
    // and check what you need by calling #getCellIdentity.
    
    final List allCellInfo = manager.getAllCellInfo();
    for (CellInfo cellInfo : allCellInfo) {
        if (cellInfo instanceof CellInfoGsm) {
            CellIdentityGsm cellIdentity = ((CellInfoGsm) cellInfo).getCellIdentity();
            //TODO Use cellIdentity to check MCC/MNC code, for instance.
        } else if (cellInfo instanceof CellInfoWcdma) {
            CellIdentityWcdma cellIdentity = ((CellInfoWcdma) cellInfo).getCellIdentity();
        } else if (cellInfo instanceof CellInfoLte) {
            CellIdentityLte cellIdentity = ((CellInfoLte) cellInfo).getCellIdentity();
        } else if (cellInfo instanceof CellInfoCdma) {
            CellIdentityCdma cellIdentity = ((CellInfoCdma) cellInfo).getCellIdentity();
        } 
    }
    

    In AndroidManifest add permission:

    
    
    

    To get network operator you can check mcc and mnc codes:

    • https://en.wikipedia.org/wiki/Mobile_country_code (general information).
    • https://clients.txtnation.com/hc/en-us/articles/218719768-MCCMNC-mobile-country-code-and-mobile-network-code-list- (quite full and quite latest list of operators).

    For API >=22:

    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final List activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    for (SubscriptionInfo subscriptionInfo : activeSubscriptionInfoList) {
        final CharSequence carrierName = subscriptionInfo.getCarrierName();
        final CharSequence displayName = subscriptionInfo.getDisplayName();
        final int mcc = subscriptionInfo.getMcc();
        final int mnc = subscriptionInfo.getMnc();
        final String subscriptionInfoNumber = subscriptionInfo.getNumber();
    }
    

    For API >=23. To just check if phone is dual/triple/many sim:

    TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    if (manager.getPhoneCount() == 2) {
        // Dual sim
    }
    

提交回复
热议问题