废话不多说,先上代码:
/**
* 获取手机内部空间大小
* @return
*/
public static double getTotalInternalStorgeSize() {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSize = mStatFs.getBlockSize();
long totalBlocks = mStatFs.getBlockCount();
DecimalFormat df = new DecimalFormat("#.00");
// 这里忽略至小数点后两位,不做四舍五入
return Double.valueOf(df.format(((totalBlocks * blockSize) / 1024.0 / 1024.0 / 1024.0)));
}
/**
* 获取手机内部可用空间大小
* @return
*/
public static double getAvailableInternalStorgeSize() {
File path = Environment.getExternalStorageDirectory();
StatFs mStatFs = new StatFs(path.getPath());
long blockSize = mStatFs.getBlockSize();
long availableBlocks = mStatFs.getAvailableBlocks();
Decima