- /**
- * 获得SD卡总大小
- *
- * @return
- */
- 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卡剩余容量,即可用大小
- *
- * @return
- */
- 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);
- }
- /**
- * 获得机身内存总大小
- *
- * @return
- */
- 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);
- }
- /**
- * 获得机身可用内存
- *
- * @return
- */
- 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);
- }
Android获取SD卡总容量,可用大小,机身内存总容量及可用大小的系统方法
最新推荐文章于 2023-03-11 11:24:42 发布