android存储空间的检测

1)SD卡剩余空间的大小

public long getAvailaleSize() {
  // 取得sdcard文件路径
  File path = Environment.getExternalStorageDirectory();
  StatFs stat = new StatFs(path.getPath());
  /* 获取block的SIZE */
  long blockSize = stat.getBlockSize();
  /* 空闲的Block的数量 */
  long availableBlocks = stat.getAvailableBlocks();
  /* 返回bit大小值 */
  //return availableBlocks * blockSize;
  return (availableBlocks * blockSize)/1024 /1024;
  // (availableBlocks * blockSize)/1024 KIB 单位
  // (availableBlocks * blockSize)/1024 /1024 MIB单位
 }

(2)SD卡的大小

public long getAllSize() {
  File path = Environment.getExternalStorageDirectory();
  StatFs stat = new StatFs(path.getPath());
  /* 获取block的SIZE */
  long blockSize = stat.getBlockSize();
  /* 块数量 */
  long availableBlocks = stat.getBlockCount();
  /* 返回bit大小值 */
  return availableBlocks * blockSize/1024/1024;
 }

(3)系统剩余空间

public static long getAvailaleSize(String dev){
  long blockSize;
  long availCount;
  File root = Environment.getRootDirectory(); 
  StatFs sf = new StatFs(root.getPath()); 
  blockSize = sf.getBlockSize(); 
  availCount = sf.getAvailableBlocks(); 
  return (availCount*blockSize)/1024/1024;
  }  
 }

你可能感兴趣的:(Android,android,存储,path,file,string)