Android 5.0, SIM_STATE_ABSENT returns false 对于第二个插槽即使存在 Sim 卡也是如此
Android 5.0, SIM_STATE_ABSENT returns false for the second slot even if Sim card is present
我一直在尝试在我的应用程序中显示 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 卡槽总是 returns false。
有人遇到过同样的问题吗? Android 系统显示 gsmStrength,但为什么 Telephony Manager 中的 SIM_STATE_ABSENT 返回 false?
一般来说,Android系统如何显示正确的值。他们在内部听什么 ??
回答有点晚,但原因是双卡的东西是在 API 级别 22 中添加的,即 Android 5.1,你有 Android 5.0,这是 API 级别 21。
在这里查看详细信息:
https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoForSimSlotIndex(int)
我一直在尝试在我的应用程序中显示 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 卡槽总是 returns false。
有人遇到过同样的问题吗? Android 系统显示 gsmStrength,但为什么 Telephony Manager 中的 SIM_STATE_ABSENT 返回 false?
一般来说,Android系统如何显示正确的值。他们在内部听什么 ??
回答有点晚,但原因是双卡的东西是在 API 级别 22 中添加的,即 Android 5.1,你有 Android 5.0,这是 API 级别 21。 在这里查看详细信息: https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoForSimSlotIndex(int)