2011-11-03 189 views
19

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

+1

[以下是完整的解决方案为您所寻找的(http://stackoverflow.com/a/17499889/703851) –

+0

尝试使用MultiSim的库:http://stackoverflow.com/a/41544422/1665964 –

回答

29

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

编辑:(2015年7月15日)

由于API 22,你可以检查使用SubscriptionManager的方法getActiveSubscriptionInfoList()多个SIM。有关Android Docs的更多详细信息。

+4

最好提及在答案中提到的SDK版本。多年以后,如果回答这个问题,这个陈述可能会误导。 – Narayanan

+0

从Android 5.2开始,android开始支持多模拟手机! – Saty

+0

有几种方法可以通过java反射检测双卡,是的,官方不可能,但在大多数情况下,有一些黑客,请参阅:http://stackoverflow.com/questions/14517338/android-check-whether-the-phone -is-dual-sim –

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卡。

+1

它如何识别哪个SIM卡处于活动状态? – gonzobrains

+0

@gonzobrains:哎呀,谢谢你的通知。更新了答案。 – Rajkiran

3

从现在起,如果手机是MTK支持的手机,您可以使用MediaTek SDK中的TelephonyManagerEx类。

看看the docs

+0

表面上[bcm_ds分支](https://code.google.com/p/android/issues/detail?id=14799#c26)或MediaTek SDK在[Android One]中是标准的(https://en.wikipedia .ORG /维基/ Android_One)。 [add](https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/b09babbf321c225b14abb013a6e1ed7041c45d06/src/com/android/providers/telephony/SmsProvider.java#275)'SmsManager.getDefault(slotId )'API。同时在Android One和MediaTek SDK中推出双SIM卡标准,并且是合作伙伴。增强[关闭“过时”](https://code.google.com/p/android/issues/detail?id=14799#c27)。 –

+0

是的,这非常有帮助 –

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