Android获得SD卡剩余容量的代码

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

File pathFile = Environment.getExternalStorageDirectory();
StatFs statfs = new StatFs(pathFile.getPath());
//获得可供程序使用的Block数量
long nAvailaBlock = statfs.getAvailableBlocks();
//获得SDCard上每个block的SIZE
long nBlocSize = statfs.getBlockSize();
//计算SDCard剩余大小MB
long nSDFreeSize = nAvailaBlock * nBlocSize / 1024 / 1024;
LogX.trace(TAG, "SD卡的剩余容量是:" + nSDFreeSize + "MB");