0

I have a device with (External storage + sd card):

enter image description here

enter image description here

With the next code I get 8GB and not 31GB, Why?

How I can get the total space available?

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() is to get readable string from bytes.

user3782779
  • 1,669
  • 3
  • 22
  • 36

1 Answers1

0

I think you will get internal storage path.

Please use below method to get external SD card path then you will use your method hope it will help you

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;
    }