检查手机sd卡的容量大小

public void CheckSize(){
File file=Environment.getExternalStorageDirectory();
StatFs statfs=new StatFs(file.getPath());
long blocksize=statfs.getBlockSize();
// 空闲的Block的数量
long availaBlock = statfs.getAvailableBlocks();
//手机内存剩余容量
String size=FormatString(blocksize*availaBlock);
Toast.makeText(this,"剩余大小"+size,0).show();
}
private String FormatString(long size){
return Formatter.formatFileSize(this,size);
}

你可能感兴趣的:(内存,手机)