My app is working for mobiles which have an SD card only. So programmatically I want to check if the SD card is available or not and how to find the SD card free space. Is it possible?
If yes, how do I do it?
Possible Reasons for SD Card Not Showing Up on Android Don't worry, the “SD card not detected on Android” problem might be caused by the following reasons: Wrong format or SD card reading errors. SD card is not compatible with the device. Wrong data transfer mode on Android.
Go to your storage settings. Navigate to Settings and then Storage. Here you should find three storage options: RAM, internal storage, and memory card. The memory card refers to your newly connected SD card.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With