当我想在我的android上看到总可用空间时,我通常会查看内部存储和外部存储(SD卡)< / em>。
基于我在一些SO答案中读到的内容,我会找到内部存储数据(可用空间,可用空间等),如下所示:
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long availableBlocks = stat.getAvailableBlocks();
//Logging added to make sure I am not going mad
Log.v(TAG,"Available Blocks: "+Long.toString(availableBlocks));
Log.v(TAG,"Total Blocks: "+Long.toString(totalBlocks));
Log.v(TAG,"Block size: "+Long.toString(blockSize));
如果我想获取我的Android设备的外部存储(SD卡),我会运行这样的代码:
FilePath path = Environment..getExternalStorageDirectory();
StatFs stat = new StatFs(Environment.getPath());
this.extblockSize = stat.getBlockSize();
long exttotalBlocks = stat.getBlockCount();
long extavailableBlocks = stat.getAvailableBlocks();
//More logging to ensure I am not mad!
Log.v(TAG,"EXTAvailable Blocks: "+Long.toString(extavailableBlocks));
Log.v(TAG,"EXTTotal Blocks: "+Long.toString(exttotalBlocks));
Log.v(TAG,"EXTBlock size: "+Long.toString(extblockSize));
我是否正确地说这是您在Android设备上阅读外部和内部存储的方式?
假设我是对的,我有点问题。当我在三星Galaxy SIII上运行上面的代码时,上面的代码返回完全相同的内存量。现在我知道我的三星有大约25GB的内存,我有一个4GB的SD卡。
但是这两段代码都返回25GB总数,这是正确的,23GB可用,这也是正确的,但仅适用于内部存储。我只是为了我的生活,无法弄清楚如何读取 SD卡的文件系统信息。请参阅下面的日志输出,了解输出的实际值。
01-14 20:49:25.485: V/VLRApplication(730): Available Blocks: 6031460
01-14 20:49:25.485: V/VLRApplication(730): Total Blocks: 6702651
01-14 20:49:25.485: V/VLRApplication(730): Block size: 4096
01-14 20:49:25.485: V/VLRApplication(730): EXTAvailable Blocks: 6031460
01-14 20:49:25.485: V/VLRApplication(730): EXTTotal Blocks: 6702651
01-14 20:49:25.485: V/VLRApplication(730): EXTBlock size: 4096
所以我必须误解这个概念。有人可以帮我澄清一下吗?对Environment.getExternalStorageDirectory()
的呼叫是否未设置SD卡的路径?我只是在AVD仿真设备中没试过这个。