6

Like below - TelephonyManager is giving details for SIM1 only ?

TelephonyManager  telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.isNetworkRoaming()
Bharat
  • 750
  • 1
  • 9
  • 20

1 Answers1

8

Before API22

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 and consult SIM2 state.

Even then, you need to handle each vendor code because probably, each vendor (Samsung/LG/Motorola) may use a different method to reach this.. so, you can expect different method names.

This question may help you: https://stackoverflow.com/a/17499889/4860513

It handles the IMEI number and maybe, you can change it to get Roaming State.

Starting at API22

From API22 onward, I think you can use SubscriptionManager

SubscriptionManager subManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);

subManager.isNetworkRoaming(int SUBID);   

However, I'm not sure which is the initial value for SUBID (not sure if it start from 0 or 1).

I tested and for SIM1, I have to use "1". For SIM2, I have to use "2".

I think the best way is to retrieve the SUBID from SubscriptionManager.

So, I think you can try following code:

SubscriptionManager subManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subInfoList = subManager.getActiveSubscriptionInfoList();

for(int i = 0; i < subInfoList.size(); i++ ) {
    int subID = subInfoList.get(i).getSubscriptionId();
    int simPosition = subInfoList.get(i).getSimSlotIndex();

    if(subManager.isNetworkRoaming(subID))
        Log.d("TEST", "Simcard in slot " + simPosition + " has subID == " + subID + " and it is in ROAMING");
    else
        Log.d("TEST", "Simcard in slot " + simPosition + " has subID == " + subID + " and it is HOME");
}

This code needs following permission to work:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Community
  • 1
  • 1
guipivoto
  • 18,327
  • 9
  • 60
  • 75
  • Thanks for the vast info. I am using API 22 only ....above code is always giving false even if on of the SIM is in Roaming (showing R). I believe it shows correct status only when your data plan is on ? – Bharat Feb 24 '16 at 17:17
  • @Bharat I updated my answer... It tested now it is working fine... SUBID should be 1 or 2 (and not 0 or 1 as I mentioned early). – guipivoto Feb 24 '16 at 17:50
  • Your woks perfectly. Thanks man. You just did magic here for me :) – Bharat Feb 25 '16 at 14:01
  • Thanks for the information. But when i get the MCC/MNC list from the SubscriptionManager list which have 2 SIM there were both value are same. please help me how to find MCC/MNC for Both SIM? – Chirag Parmar Dec 28 '17 at 11:27
  • Subscription ID is not always 1 or 2. Each SIM card gets it's own subId, even when its not connected the ID cannot be reused. So if the user inserts one sim into slot 1 and 2, then changes slot 2 sim to a new sim, it is id 3. Use instead https://developer.android.com/reference/android/telephony/SubscriptionManager#getActiveSubscriptionInfoForSimSlotIndex(int) – Hack5 May 08 '19 at 09:15