检测双卡Android手机中两张SIM卡的状态

时间:2011-11-03 14:03:58

标签: android sim-card

我想以编程方式检测我的双卡Android手机中是否有两张SIM卡。我找到了一个API(TelephonyManager.getSIMState()),但它适用于普通的单SIM卡手机。是否有任何API可以检测我的双SIM卡手机中是否插入了两个SIM卡?

4 个答案:

答案 0 :(得分:31)

Android不支持多个SIM,至少来自SDK。已经创建了多SIM卡设备的设备制造商正在自行创建。欢迎您与设备制造商联系,看看他们是否有SDK插件或允许您访问第二张SIM的东西。

修改 (2015年7月15日)

自API 22起,您可以使用SubscriptionManager方法getActiveSubscriptionInfoList()检查多个SIM卡。有关Android Docs的更多详情。

答案 1 :(得分:3)

从现在开始,如果手机是MTK供电的,您可以使用MediaTek SDK中的TelephonyManagerEx类。

看看the docs

答案 2 :(得分:1)

嗯,这不是万无一失的。但是如果你有两个不同网络运营商的SIM卡,你可以尝试这样的事情:

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);
}

}

理想情况下,您将获得两个SIM卡的SIM服务状态更改事件,然后您可以检查网络运营商名称或类似内容,以检查您是否有两张SIM卡。但是你需要在两个不同的网络上运行两张SIM卡。

答案 3 :(得分:0)

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());
    }