获取手机SD卡的剩余容量(MB)
/**
* 判断SD卡的剩余容量
*
*/
public long isAvaiableSpace(int sizeMb) {
long availableSpare = 0;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
String sdcard = Environment.getExternalStorageDirectory().getPath();
StatFs statFs = new StatFs(sdcard);
long blockSize = statFs.getBlockSize();
long blocks = statFs.getAvailableBlocks();
availableSpare = (blocks * blockSize) / (1024 * 1024);
Log.d("剩余空间", "availableSpare = " + availableSpare);
}
return availableSpare;
}