我已经阅读了很多与该主题相关的问题,最后能够编写这段代码
StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
long blockSize = statFs.getBlockSizeLong();
long totalSizeInternal = statFs.getBlockCountLong()*blockSize;
long freeSizeInternal = statFs.getFreeBlocksLong()*blockSize;
statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
blockSize = statFs.getBlockSizeLong();
long totalSizeExternal = statFs.getBlockCountLong()*blockSize;
long freeSizeExternal = statFs.getFreeBlocksLong() * blockSize;
Log.d("printingDetails", totalSizeExternal + "");
Log.d("printingDetails", freeSizeExternal + "");
Log.d("printingDetails", totalSizeInternal + "");
Log.d("printingDetails", freeSizeInternal + "");
Log.d("printingDetails", Environment.isExternalStorageRemovable() + "");
并且能够为我的redmi 3s手机获得此输出 freeSizeExternal :2034581504 totalSizeExternal :10486845440 freeSizeInternal :308924416 totalSizeInternal :3095707648
我的redmi 3s有一个16GB的内部存储空间,没有插入外部SD卡,可用空间超过2.1GB,当我检查micromax手机时,SD卡的容量为32GB,内部存储器为2GB,i得到以下结果,如外部存储显示大约29GB,内部存储大约700MB显示,任何人都可以解释我在这两种情况下的内部和外部尺寸,为什么它们与原始尺寸如此不同,并提供我正确的代码,显示正确的手机内部和外部记忆大小。