1.检测SD卡是否存在

if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)

2.取得SD卡路径

File sdcardDir=Environment.getExternalStorageDirectory();

3,查看文件系统的空间使用情况

StatFs statFs=new StatFs(sdcardDir.getPath());

4.查看Block size

Long blockSize=statFs.getBlockSize();

5.查看总block数量

Long totalBlocks=statFs.getBlockCount();

6.查看已经使用的Block的数量

Long availableBlocks=statFs.getAvailableBlocks();

7.得到SD卡剩余容量

int availableSpare = (int) (statFs.getBlockSize()*((long)statFs.getAvailableBlocks()-4));

8.得到SD卡剩余的容量MB

int availableSpare = (int) (stat.getBlockSize() * ((long) stat
.getAvailableBlocks() – 4)) ;
int availableMB= (int)availableSpare/1024/1024;