Like below - TelephonyManager is giving details for SIM1 only ?
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.isNetworkRoaming()
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With