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

送分小仙女□ 提交于 2019-11-26 14:34:49
CommonsWare

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.

Andrey Kopeyko

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

Take a look at the docs.

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.

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());
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!