1

Currenty I get the total storage size with:

public static long getTotalSize(String path) {
    try {
        final StatFs statFs = new StatFs(path);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            return statFs.getTotalBytes();
        } else {
            return statFs.getBlockCount() * statFs.getBlockSize();
        }
    } catch (Exception e) {
        return 0;
    }
}

As path I am using Environment.getExternalStorageDirectory().getAbsolutePath(). This results in 54,0 GB. Problem is that the device has a size of 64 GB.

How to detect the missing 10 GB?

Megaetron
  • 1,154
  • 2
  • 15
  • 29
  • Maybe this will help: https://stackoverflow.com/questions/14531806/it-is-possible-to-get-total-storage-capacity – yoav Apr 01 '18 at 20:14

1 Answers1

0

StatFs - Retrieve overall information about the space on a filesystem. This is a wrapper for Unix statvfs().

From API level 18 we use

long getTotalBytes - The total number of bytes supported by the file system. 

For older API use

int getBlockCount ()
int getBlockSize ()

StatFs stat = new StatFs(**path**);
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();

As path You use Environment.getExternalStorageDirectory(), please review this value. In devices with multiple shared/external storage directories, this directory represents the primary storage that the user will interact with.

You need use string values of path like this: "/mnt/external_sd/" "/mnt/extSdCard/"

You can retreive list of all /mnt/ devices and use one of this values.

File mntDir = new File("/mnt/");
if(mntDir.isDirectory()){ 
String[] dirList = mntDir.list();...}

or something like

var file=new Java.IO.File("storage/");
var listOfStorages=file.ListFiles();

or

String[] externals = System.getenv("SECONDARY_STORAGE").split(":");
Mark Martin
  • 372
  • 3
  • 8