In my application I want to check whether the SD-Card is present (asin mounted) or not. When I try to run the application I am getting "sd-card is mounted" even though its not there.
Code
public boolean isSDCardPresent() {
return android.os.Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}
The above code always returns true even if the sd-card is not present.
The external (removable) Sd path varies from device to device, I also couldn't figure out a single way to check its availability, so I wrote a method, which iterates through all the different ext paths that the different manufacturers use, and then it finds the exact match. Returns true if the folder is found & the card is inserted in the phone.
Note: I used StreamSupport library inside the method, so you'll need to download the jar file and add it to libs folder of your project and that's it, it'll work!
P.S. I tested and verified it on a few HTC and Samsung devices.