获取手机SD卡的剩余容量(MB)

 /**
* 判断SD卡的剩余容量
*
*/
public long isAvaiableSpace(int sizeMb) {
long availableSpare = 0;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
String sdcard = Environment.getExternalStorageDirectory().getPath();
StatFs statFs = new StatFs(sdcard);
long blockSize = statFs.getBlockSize();
long blocks = statFs.getAvailableBlocks();
availableSpare = (blocks * blockSize) / (1024 * 1024);
Log.d("剩余空间", "availableSpare = " + availableSpare);
}
return availableSpare;
}

 

posted @ 2012-03-01 19:41  程序学习笔记  阅读(352)  评论(0编辑  收藏  举报