Search code examples
androidtelephonymanager

MNC and MCC of a secondary SIM


I know that using TelephonyManager we can get MNC and MCC of our network provider,

TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = tel.getNetworkOperator();

if (networkOperator != null) {
    int mcc = Integer.parseInt(networkOperator.substring(0, 3));
    int mnc = Integer.parseInt(networkOperator.substring(3));
}

But I was able to get MNC and MCC data of only primary sim. I would like to know is there a way to fetch mnc,mcc,lac and cellid's of Secondary sim of a device in android.


Solution

  • Before API 22, it will be hard to achieve what you want.

    I believe that before API 22, dual SIM was not originally supported by Android. So, each Mobile vendor should have its own implementation. Maybe, you should get their APIs/SDKs and include them to your project. Only this way, you will have access to their APIs.

    From API22 onward, I think you can use SubscriptionManager

        int mccSlot1 = -1;
        int mccSlot2 = -1;
        int mncSlot1 = -1;
        int mncSlot2 = -1;
    
        SubscriptionManager subManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    
        if(subManager.getActiveSubscriptionInfoCount() >= 1) {
            mccSlot1 = subManager.getActiveSubscriptionInfo(0).getMcc();
            mncSlot1 = subManager.getActiveSubscriptionInfo(0).getMnc();
        }
    
        if(subManager.getActiveSubscriptionInfoCount() >= 2) {
            mccSlot2 = subManager.getActiveSubscriptionInfo(1).getMcc();
            mncSlot2 = subManager.getActiveSubscriptionInfo(1).getMnc();
        }
    

    Question https://stackoverflow.com/a/32871156/4860513 mention the same Android Limitation. So, I really believe it is not possible to achieve that before API22 with pure Android SDK.