I'm trying to find a way to find the total size and free space of a mounted SD card on a phone, from my research on SOF and on the Android devs site I was able to find the method getExternalStorageDirectory() but according to the Android API this returns a directory that is not necessarily external:
"Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer."
So I gather from the way that is worded that the "external storage" directory can actually be apart of multiple physical storage devices (internal and external memory). And from my testing that's what I've found as the size that is being returned by using this method is around 1.5x the size of my actual SD card.
So my question is, is there a programmatical way to return the total size and available space just on the SD card? The phone itself can give me that information so I feel like there should be a way but I'm at a loss right now... any help would be appreciated!
EDIT: This is the code I'm currently using for total size
private long TotalSDMemory(){
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getAbsolutePath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long totalSpace = totalBlocks * blockSize;
Log.d(TAG,"Size of total SD Memory: "+totalSpace);
Log.d(TAG, "External storage emulated: "+Environment.isExternalStorageEmulated());
return totalSpace;
}
Edit(2): I didn't know this mattered but I have a Samsung Galaxy S3 which is what I am using to test the code, apparently Samsung has a different file structure for their external memory. Here is a link that should help anyone else get the correct size: Get size of SD card in Samsung phones