我有一个设备(外部存储+ SD卡):
使用下一个代码我得到8GB而不是31GB,为什么?
如何获得总空间?
private String getAvailableExternalMemorySize() {
if (externalMemoryAvailable()) {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return formatSize(availableBlocks * blockSize);
} else {
return "Error";
}
}
formatSize()是从字节中获取可读字符串。
答案 0 :(得分:0)
我认为你将获得内部存储路径。
请使用以下方法获取外部SD卡路径然后您将使用您的方法希望它能帮助您
private String getAvailableExternalMemorySize() {
if (externalMemoryAvailable()) {
File path = new File(getExternalSdCardPath());
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return formatSize(availableBlocks * blockSize);
} else {
return "Error";
}
}
public static String getExternalSdCardPath() throws Throwable
{
String m_externalPath;
m_externalPath = System.getenv("SECONDARY_STORAGE");
return m_externalPath;
}