获取SD卡容量大小:
/**
* 获取SD卡的大小信息
*/
public void getSDcardSize() {
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
// 获取SDCard上每个block的SIZE
long blockSize = stat.getBlockSize();
// 获取SDCard上BLOCK总数
long totalBlocks = stat.getBlockCount();
// 获取可供程序使用的Block的数量
long availaBlocks = stat.getAvailableBlocks();
// 获取剩下的所有Block的数量(包括预留的一般程序无法使用的块)
long freeBlocks = stat.getFreeBlocks();
//SD卡总大小 MB
long totalBytes = blockSize*totalBlocks/1024/1024;
// 计算 SDCard 剩余大小MB
long sdFreeSize = availaBlocks*blockSize/1024/1024;
// 计算 SDCard 剩余大小MB
long frerSize = freeBlocks*blockSize/1024/1024;
System.out.println("----------SD总容量" + totalBytes + "MB,可用容量:" + sdFreeSize + "MB, free:"+frerSize+"MB");
System.out.println(Integer.MAX_VALUE);
} else {
//SDcard is not found
}
}