How to get carrier name from dual sim phone Android?

后端 未结 3 656
臣服心动
臣服心动 2021-01-07 06:30

I am able to get the carrier name from duel SIM phone.

I used the following code but it works only single SIM phone.

TelephonyManager telephonyManage         


        
相关标签:
3条回答
  • 2021-01-07 06:49

    Fortunately there are several native solutions I've found while searching the way to get 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<CellInfo> 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:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    </manifest>
    

    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<SubscriptionInfo> 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
    }
    
    0 讨论(0)
  • 2021-01-07 06:49

    As android doesn't support multiple sim atleast below than API level 22.

    Since API 22, you can check for multiple SIMs using SubscriptionManager's method getActiveSubscriptionInfoList(). More details on https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoList%28%29.

    For more detail please refer below link Detect the status of two SIM cards in a dual-SIM Android phone

    0 讨论(0)
  • 2021-01-07 07:01

    Using "SubscriptionManager" we can know the Carrier names of the dual sim of the android mobile.

    SubscriptionManager subscriptionManager=(SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    
                List<SubscriptionInfo> subscriptionInfoList=subscriptionManager.getActiveSubscriptionInfoList();
    
                if(subscriptionInfoList!=null && subscriptionInfoList.size()>0){
                   for(SubscriptionInfo info:subscriptionInfoList){
                      String carrierName = info.getCarrierName().toString();
                       String mobileNo=info.getNumber();
                       String countyIso=info.getCountryIso();
                       int dataRoaming=info.getDataRoaming();
    
                   }
    
                }
    
    0 讨论(0)
提交回复
热议问题