//判断SD卡是否可用
if (Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
// 存储容量计算
StatFs state = new StatFs(Environment.getExternalStorageDirectory()
.getAbsolutePath());
long blockSize = state.getBlockSize();
long blockCount = state.getBlockCount();
long availableCount = state.getAvailableBlocks();
String totalSpace = String.format("%.2f", blockCount * blockSize
/ Math.pow(1024, 3)); /* 存储空间大小 in GB */
String freeSpace = String.format("%.2f", availableCount * blockSize
/ Math.pow(1024, 3)); /* 可用的存储空间大小 in GB */
saveSpace.setText("存储空间:共" + totalSpace + "G\t剩余:" + freeSpace
+ "G");
}
android判断SD卡信息
最新推荐文章于 2021-05-27 02:10:36 发布