Detect the status of two SIM cards in a dual-SIM Android phone
Asked Answered
K

4

20

I want to detect whether two SIM cards are there in my dual-SIM android phone programmatically. I found one API (TelephonyManager.getSIMState()), but it is for normal single-SIM phones. Are there any APIs to detect whether or not two SIMs are inserted in my dual-SIM phone?

Kymberlykymograph answered 3/11, 2011 at 14:3 Comment(2)
Here is full solution for what you are looking forBettencourt
Try use MultiSim library: https://mcmap.net/q/88841/-android-dual-sim-card-apiIdden
F
35

Android does not support multiple SIMs, at least from the SDK. Device manufacturers who have created multi-SIM devices are doing so on their own. You are welcome to contact your device manufacturer and see if they have an SDK add-on or something that allows you to access the second SIM.

Edit: (15th July, 2015)

Since API 22, you can check for multiple SIMs using SubscriptionManager's method getActiveSubscriptionInfoList(). More details on Android Docs.

Fashionable answered 3/11, 2011 at 14:32 Comment(7)
It would be better to mention the version of SDK that is been mentioned in the answer. When this answer is viewed after many years, the statement made might mislead.Zachar
From Android 5.2 onwards android started supporting multi sim mobiles!Might
there are several ways to detect dual sim via java reflection, yes officially not possible, but in most cases there is some hacks, see: #14517838Grout
@Fashionable The problem with getActiveSubscriptionInfoList() is that it only returns the active SIM's, ie, if a dual sim device only has a SIM on it, getActiveSubscriptionInfoList() will return a list with only one element. As of API 23, TelepfonyManager.getPhoneCount() returns the number of SIM slots.Stirk
Is it possible to get which one is set as the default for a phone call (if there is any) ?Zeus
@androiddeveloper: I have no idea, sorry.Fashionable
@Fashionable Seems it's this one: developer.android.com/reference/android/telecom/… . Not sure what else I can put as a parameter but this works fine: telecomManager.getDefaultOutgoingPhoneAccount("tel") . Found answer from here: https://mcmap.net/q/89203/-how-to-check-which-sim-is-set-as-default-sim-in-android-programaticallyZeus
C
3

From now, if the phone is MTK powered one, you can use TelephonyManagerEx class from MediaTek SDK.

Take a look at the docs.

Cyathus answered 28/11, 2014 at 18:57 Comment(2)
Ostensibly bcm_ds branch or MediaTek SDK to be standard in Android One. Both add the SmsManager.getDefault(slotId) API. Launched simultaneously dual sim standard in Android One and MediaTek SDK and are partners. Enhancement closed "obsolete".Importunate
Yes this is very helpfulHeir
N
2
final SubscriptionManager subscriptionManager = SubscriptionManager.from(getApplicationContext());
    final List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    int simCount = activeSubscriptionInfoList.size();
    btnBack.setText(simCount+" Sim available");
    Log.d("MainActivity: ","simCount:" +simCount);

    for (SubscriptionInfo subscriptionInfo : activeSubscriptionInfoList) {
        Log.d("MainActivity: ","iccId :"+ subscriptionInfo.getIccId()+" , name : "+ subscriptionInfo.getDisplayName());
    }
Nika answered 20/12, 2017 at 7:54 Comment(0)
J
1

Well, this is not fool proof. But if you have two SIMs which are on two different network operators you can try something like this:

PhoneServiceStateListener listener = new PhoneServiceStateListener(this);
tm.listen(listener, PhoneStateListener.LISTEN_SERVICE_STATE);


.
.
.
class PhoneServiceStateListener extends PhoneStateListener {
Context context = null;

public PhoneServiceStateListener(Context context) {
    this.context = context;
}

public PhoneServiceStateListener() {
}

@Override
public void onServiceStateChanged(ServiceState serviceState) {

    if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
        //You get this event when your SIM is in service.
        //If you get this event twice, chances are more that your phone is Dual SIM.
        //Alternatively, you can toggle Flight Mode programmatically twice so
        //that you'll get service state changed event.
    }
    super.onServiceStateChanged(serviceState);
}

}

Ideally you'll get SIM service state changed event for both the SIMs and then you can check for network operator name or something like that to check if you have two SIM cards. But you need to have two SIM cards running on two different networks.

Jackass answered 31/1, 2013 at 6:49 Comment(2)
How does it discern which SIM card is active?Halfcaste
@Halfcaste : Oops, thanks for informing. Updated the answer.Jackass

© 2022 - 2024 — McMap. All rights reserved.