4

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 telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));
Anjali Tripathi
  • 1,477
  • 9
  • 28
Mahbub Mukul
  • 333
  • 3
  • 18
  • 2
    Have a look at this https://developer.android.com/intl/pt-br/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoList%28%29 – Jas Jan 11 '16 at 05:23
  • this might help http://stackoverflow.com/a/32304799/3134215 – Ravi Jan 11 '16 at 05:29

3 Answers3

7

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:

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
}
oxied
  • 1,773
  • 19
  • 14
1

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();

               }

            }
Kona Suresh
  • 1,836
  • 1
  • 15
  • 25
  • what is the difference between getcarriername() and getdisplayname(). I am getting No Service as carrier name when Aeroplane mode is on and getDisplayname as Airtel. I want to ask which to use to show user the SIM Operator name. – Aman Verma Feb 09 '19 at 19:38
0

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

Community
  • 1
  • 1
Anjali Tripathi
  • 1,477
  • 9
  • 28
  • what is the difference between getcarriername() and getdisplayname(). I am getting No Service as carrier name when Aeroplane mode is on and getDisplayname as Airtel. I want to ask which to use to show user the SIM Operator name. – Aman Verma Feb 09 '19 at 19:37