I need to check the amount of space available on the memory card, I currently use this method for verification:
public static float megabytesAvailable() {
File f = Environment.getExternalStorageDirectory()
StatFs stat = new StatFs(f.getPath());
long bytesAvailable = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
bytesAvailable = stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
}
else {
bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
}
return bytesAvailable / (1024.f * 1024.f * 1024.f);
}
For older versions (up to 4.3.3) is working properly, however when I run this same method on a Galaxy Grand Prime Duos (SM-G531H) with version 5.1.1 of Android, the above method returns me the space available on the device's internal storage and not on the memory card. Does anyone know what's wrong with the code?