How to get carrier name from dual sim phone Android with API level 16?

1.5k views Asked by At

I am creating an app with minimum sdk version 16.My question is how to get the carrier name of both the carriers in a dual sim phone.

I used this code but it dosenot work with sdk v16

TelephonyManager telephonyManager = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE));

And also I want to get the name of the carrier in string format.

1

There are 1 answers

0
SAIR On BEST ANSWER

SubscriptionManager is available in API 22

use the following code to get carrier names for dual sim phone

SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    List<String> carrierNames = new ArrayList<>();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
        List<SubscriptionInfo> subscriptionInfos = subscriptionManager.getActiveSubscriptionInfoList();
        for (int i = 0; i < subscriptionInfos.size(); i++) {
            carrierNames.add(subscriptionInfos.get(i).getCarrierName().toString());
        }
    }