获得SD卡总大小
private String getSDTotalSize() { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return Formatter.formatFileSize(MainActivity.this, blockSize * totalBlocks); }
获得sd卡剩余容量,即可用大小private String getSDAvailableSize() { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return Formatter.formatFileSize(MainActivity.this, blockSize * availableBlocks); }
获得机身内存总大小private String getRomTotalSize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); return Formatter.formatFileSize(MainActivity.this, blockSize * totalBlocks); }
获得机身可用内存private String getRomAvailableSize() { File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return Formatter.formatFileSize(MainActivity.this, blockSize * availableBlocks); }