How to get the disk free size?
(Android phone – how-to/example)
This is a little different from Java, Android has a separate package that partly deals with this problem.
Use
android.os.Environment to get the sdcard (if needed).
android.os.StatFs – << Retrieve overall information about the space on a filesystem. This is a Wrapper for Unix statfs(). >>
The function is straight forward:
public static long GetFreeSpaceB()
{
try
{
String storageDirectory = Environment.getExternalStorageDirectory().toString();
StatFs stat = new StatFs(storageDirectory);
return stat.getAvailableBlocks() * stat.getBlockSize();
}
catch (Exception ex)
{
return -1;
}
}












