Get operator details for dual SIM android phone
Asked Answered
A

4

3

I am working on an app where I need details of user's SIM his phone number, imei number and operator . so far I have achieved his IMEI's numbers refering this answer, is his device single sim or dual SIM. How do I get his number of both the SIM and the name of operator for both the connections.

Adjunct answered 4/3, 2014 at 11:14 Comment(0)
T
3

Try this, works for me:

TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String carrierName = manager.getNetworkOperatorName();
Trivial answered 16/7, 2014 at 16:22 Comment(2)
There is not support in the Android SDK for multiple SIM cards. Only we can get the name of the Current Network Operator or SIM operator and in case you dont have sim the result will be "". This will work but only for the main operator.Trivial
From API 22, now you can check for multiple SIM cards. Check out Android DocsSadler
A
3

Fortunately there are several native solutions. Hope this will help somebody.

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
}
Asberry answered 5/11, 2016 at 15:7 Comment(1)
Seems for SubscriptionManager you need another dangerous permission READ_PHONE_STATE. Also, first solution will return not sim, but towers info.Hardbitten
I
1

try here:

private List<String> getNetworkOperator(final Context context) {
    // Get System TELEPHONY service reference
    List<String> carrierNames = new ArrayList<>();
    try {
        final String permission = Manifest.permission.READ_PHONE_STATE;
        if ( (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) && (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED) ){
            final List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
            for (int i = 0; i < subscriptionInfos.size(); i++) {
                carrierNames.add(subscriptionInfos.get(i).getCarrierName().toString());
            }

        } else {
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            // Get carrier name (Network Operator Name)
            carrierNames.add(telephonyManager.getNetworkOperatorName());

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return carrierNames;
}
Innocency answered 26/10, 2016 at 10:11 Comment(1)
"SubscriptionManager.from(context).getActiveSubscriptionInfoList()" works well in both single and dual sims context, contrary to "telephonyManager.getNetworkOperatorName()" which more often than not returns only one carrier name in dual sims.Pink
G
1
        // Use this code, it will provide all the info realated both sim card 

        Required Permission:
        <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 

            if (getSimInfo(context).get(0) != null) {  // SIM 1
                               getSimInfo(context).get(0).getMcc()); 
                               getSimInfo(context).get(0).getMnc());
                            } else {
                               Log.d("Sim card", "Sim card not available");
                            }
                            if (getSimInfo(context).get(1) != null) { // SIM 2
                                getSimInfo(context).get(1).getMcc());
                                getSimInfo(context).get(1).getMnc());
                            } else {
                               Log.d("Sim card", "Sim card not available");
                            }
                            if (getNetworkOperator(context).get(0) != null) { // SIM 1
     (String)getSimInfo(context).get(0).getCarrierName());
                            } else {
                               Log.d("Sim card", "Sim card not available");
                            }
                            if (getNetworkOperator(context).get(1) != null) {// SIM 2 
 (String)getSimInfo(context).get(1).getCarrierName());
                            } else {
                              Log.d("Sim card", "Sim card not available");
                            }

        // getSimInfo
        public List<SubscriptionInfo> getSimInfo(Context context) {
                SubscriptionManager subManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
                List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
                subscriptionInfoList = subManager.getActiveSubscriptionInfoList();
                Log.d("LIST LIST", subscriptionInfoList.toString());
                if (subscriptionInfoList == null) {
                    Toast.makeText(context, "address not found", Toast.LENGTH_SHORT).show();
                }
                return subscriptionInfoList;
            }

            // getNetworkOperator 
            public List<String> getNetworkOperator(final Context context) {
                // Get System TELEPHONY service reference
                List<String> carrierNames = new ArrayList<>();
                try {
                    final String permission = android.Manifest.permission.READ_PHONE_STATE;
                    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) && (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED)) {
                        final List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
                        for (int i = 0; i < subscriptionInfos.size(); i++) {
                            carrierNames.add(subscriptionInfos.get(i).getCarrierName().toString());
                        }

                    } else {
                        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                        // Get carrier name (Network Operator Name)
                        carrierNames.add(telephonyManager.getNetworkOperatorName());
            enter code here
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return carrierNames;
            }
Geneva answered 25/1, 2019 at 7:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.