关于SD卡总容量和可用容量的获取.代码如下:
private void getSDInfo(){
String SDStatus = Environment.getExternalStorageState();
if(Environment.MEDIA_MOUNTED.equals(SDStatus)){
File path = Environment.getExternalStorageDirectory();
StatFs statFs = new StatFs(path.getAbsolutePath());
long blockSize = statFs.getBlockSize();
long availableBlocks = statFs.getAvailableBlocks();
long totalBlocks = statFs.getBlockCount();
Log.i(TAG, "SD总容量为:"+formatFileSize(blockSize * totalBlocks));
Log.i(TAG,"SD可用容量为:"+formatFileSize(blockSize * availableBlocks));
}else{
Log.i(TAG, "SD卡不存在");
}
}
private String formatFileSize(long number){
return Formatter.formatFileSize(this, number);
}