Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can TelephonyManager gives details for the SIM 2 as well, Like isRoaming etc ..?

Tags:

android

Like below - TelephonyManager is giving details for SIM1 only ?

TelephonyManager  telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.isNetworkRoaming()
like image 216
Bharat Avatar asked Feb 24 '16 11:02

Bharat


1 Answers

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" />
like image 109
W0rmH0le Avatar answered Dec 17 '22 18:12

W0rmH0le