Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Created October 18, 2013 10:18
Show Gist options
  • Save daichan4649/7039499 to your computer and use it in GitHub Desktop.
Save daichan4649/7039499 to your computer and use it in GitHub Desktop.
disk size check
/** 有効サイズ(10MB) */
private static final long AVAILABLE_DISK_SIZE = 10 * 1024 * 1024;
public static boolean isDiskAvailable() {
return isDiskAvailable(AVAILABLE_DISK_SIZE);
}
public static boolean isDiskAvailable(long limitSize) {
long diskAvailableSize = getDiskAvailableBytes();
return diskAvailableSize > limitSize;
}
public static long getDiskAvailableBytes() {
StatFs sf = new StatFs("/mnt/sdcard");
long blockSize = sf.getBlockSize(); // byte
long availableBlocks = sf.getAvailableBlocks();
return blockSize * availableBlocks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment