Check whether the SD card is available or not programmatically

Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
Boolean isSDSupportedDevice = Environment.isExternalStorageRemovable();

if(isSDSupportedDevice && isSDPresent)
{
  // yes SD-card is present
}
else
{
 // Sorry
}

Accepted answer doesn't work for me

Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

In case if device has a built-in storage, it returns true; My solution is that to check the external files directory count, if there is more than one, device has sdcard. It works and I tested it for several devices.

public static boolean hasRealRemovableSdCard(Context context) {
    return ContextCompat.getExternalFilesDirs(context, null).length >= 2;
}