代码如下 | 复制代码 |
//1.获取内存可用大小,内存路径 String path=Environment.getDataDirectory().getAbsolutePath(); String memoryAvaliSpace= Formatter.formatFileSize(this,getAvailSpace(path)); //2.获取sd卡可用大小,sd卡路径 String sdPath=Environment.getExternalStorageDirectory().getAbsolutePath(); String sdAvaliSpace= Formatter.formatFileSize(this,getAvailSpace(sdPath));
privatelonggetAvailSpace(String path) { //获取可用内存大小 StatFs statfs=newStatFs(path); //获取可用区块的个数 longcount=statfs.getAvailableBlocks(); //获取区块大小 longsize=statfs.getBlockSize(); //可用空间总大小 returncount*size; } |