这是一个工具类,如果SD卡的剩余空间小于某个值返回false,如果有足够的控件,则返回true.
public class SDCardSizeUtil {
public static boolean isAvaiableSpace(int sizeMb) {
boolean ishasSpace = false;
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();
long availableSpare = (blocks * blockSize) / (1024 * 1024);
Log.d("剩余空间", "availableSpare = " + availableSpare);
if (availableSpare > sizeMb) {
ishasSpace = true;
}
}
return ishasSpace;
}
}