Android中如何判断sd卡容量是否小于某值
当在电话通话录音、照相、录音机等中全部要用到T卡容量大小胡判断:[java]
public static boolean isAvaiableSpace(int sizeMb){
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
String sdcard = Environment.getExternalStorageDirectory().getPath();
// File file = new File(sdcard);
StatFs statFs = new StatFs(sdcard);
long blockSize = statFs.getBlockSize();
long blocks = statFs.getAvailableBlocks();
long availableSpare = (blocks*blockSize)/(1024*1024);
// long availableSpare = (long) (statFs.getBlockSize()*((long)statFs.getAvailableBlocks()-4))/(1024*1024);//以比特计算 换算成MB
System.out.println("availableSpare = " + availableSpare);
if(sizeMb>availableSpare){
return false;
}else{
return true;
}
}
return false;
}
通过上面的方法,可以进行SD卡容量大小的判断了。
摘自 Kylin麒麟
补充:移动开发 , Android ,