2

I know from sdk level android.os.Build.VERSION_CODES.LOLLIPOP_MR1 we get subscriptionInfoList as subscriptionManager.getActiveSubscriptionInfoList(); and by using this we will identify all the supported sim information.

I need getting the same in android lower versions. Anybody can help me ?

rajeesh
  • 937
  • 10
  • 11
  • please see this link.i hope this will help you. http://stackoverflow.com/questions/22170425/get-operator-details-for-dual-sim-android-phone – LoveAndroid Nov 02 '16 at 05:46

1 Answers1

1

Fortunately there are several native solutions.

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 newest devices you can use newest APIs.

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
  • thank you.this is fine but i need to support my app from version 14. So this solution is not practical for such lower versions. – rajeesh Nov 10 '16 at 09:47
  • CellIdentity seems to reveal the MCC and MNC about the network you're currently on, but not the MCC and MNC of the carrier/country that the SIM card belongs to. I am currently using a Safaricom SIM card from Kenya, while in America. This card roams on T-Mobile, so I get the MCC/MNC values of 310 and 260, respectively. For many applications, this solution will not suffice. – rrbrambley Jan 24 '17 at 19:19