Created
October 18, 2013 10:18
-
-
Save daichan4649/7039499 to your computer and use it in GitHub Desktop.
disk size check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 有効サイズ(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