Below you can find code which help you find if SIM card available in the device.
There two solutions. One for Android API less than 22 and for Android API greater than or equal to 22.
Problem that dualsim support added in API-22. And we should deal with devices which support dual sim and has API less than 22.
So solution for API less than 22.
public boolean isSimAvailable(Context context){
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager.getSimSerialNumber() != null){
return true;
}
return false;
}You can ask why I’m not checking for phone number. I do this because the phone number is not 100% available. Sim card serial number always available.
Second solution for API greater than or equal to 22
public boolean isSimAvailable(Context context){
SubscriptionManager sManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
SubscriptionInfo infoSim1 = sManager.getActiveSubscriptionInfoForSimSlotIndex(0);
SubscriptionInfo infoSim2 = sManager.getActiveSubscriptionInfoForSimSlotIndex(1);
if(infoSim1 != null || infoSim2 != null) {
return true;
}
return false;
}And here is universal solution:
public boolean isSimAvailable(Context context){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager sManager = (SubscriptionManager) context.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) App.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager.getSimSerialNumber() != null){
return true;
}
}
return false;
}Let me know your solution in comments.




