我一直试图在我的应用程序中显示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;
}这段代码非常好。但是在AndroidLollipo5.0中,即使插入sim卡,第二个Sim插槽也总是返回false。
有没有人面临过同样的问题?Android系统显示gsmStrength,但是为什么电话管理器中的SIM_STATE_ABSENT返回false?
一般情况下,Android系统如何显示正确的值。他们内部在听什么??
发布于 2017-03-10 13:10:43
回答有点晚,但原因是在API级别22,即Android5.1中添加了双sim功能,还有Android5.0,也就是API级别21。查看这里的详细信息:https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoForSimSlotIndex(int)
https://stackoverflow.com/questions/36351449
复制相似问题