即使存在SIM卡,Android 5.0,SIM_STATE_ABSENT也会为第二个插槽返回false

时间:2016-04-01 08:22:12

标签: android android-5.0-lollipop telephonymanager

我一直在尝试在我的应用中显示gsmSignalStrength()。以下代码用于检查是否存在sim

private boolean checkIfSimIsPresent() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        SubscriptionManager sManager = (SubscriptionManager) mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
        SubscriptionInfo infoSim1 = sManager.getActiveSubscriptionInfoForSimSlotIndex(0);
        SubscriptionInfo infoSim2 = sManager.getActiveSubscriptionInfoForSimSlotIndex(1);
        if(infoSim1 != null || infoSim2 != null) {
            return true;
        }
    } else {
        TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT){
            return true;
        }
    }
    return false;
}

这段代码非常好。但在Android Lollipop 5.0中,即使插入了SIM卡,第二个SIM卡插槽也会返回false。

有没有人遇到同样的问题? Android系统显示gsmStrength,但为什么Telephony Manager中的SIM_STATE_ABSENT返回false?

通常,Android系统如何显示正确的值。他们在内部听什么?

1 个答案:

答案 0 :(得分:0)

回答有点迟,但原因是在API级别22(Android 5.1)中添加了Dual-sim,你有Android 5.0,这是API级别21。 在这里查看详细信息: https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoForSimSlotIndex(int)