I have been trying to display gsmSignalStrength() in my app. The following code is used for checking if sim is present
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;
}
This piece of code very fine. But In Android Lollipop 5.0, the second sim slot always returns false even if Sim card is inserted.
Has anyone faced the same issue? The Android System displays the gsmStrength, but why is SIM_STATE_ABSENT in Telephony Manager returning false ?
Generally, how do Android System display correct value. What do they listen to internally ??
A bit late to answer, but the reason is that the Dual-sim thing was added in API level 22, which is Android 5.1, you have Android 5.0, which is API level 21. Check the details here: https://developer.android.com/reference/android/telephony/SubscriptionManager.html#getActiveSubscriptionInfoForSimSlotIndex(int)