Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法获取设备总存储空间_Android_Android External Storage - Fatal编程技术网

Android 无法获取设备总存储空间

Android 无法获取设备总存储空间,android,android-external-storage,Android,Android External Storage,我有一个带有外部存储+sd卡的设备: 下一个代码是8GB而不是31GB,为什么 如何获得可用的总空间 private String getAvailableExternalMemorySize() { if (externalMemoryAvailable()) { File path = Environment.getExternalStorageDirectory(); StatFs stat = new StatFs(path.getPath());

我有一个带有外部存储+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是从字节中获取可读字符串。

我认为您将获得内部存储路径

请使用下面的方法获取外部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;
    }

您是否尝试过此操作:?在某些设备中工作,而在其他所有使用sd卡的设备中,我发现statfs失败,错误号:2