I have a App that uses 3 kinds of storage: The internal storage, a external SD and if Version >= 6.0 a SD which is formatted as internal.
I get the external SD path by using getExternalFilesDirs()
, the internal Storage by getFilesDir()
and the adopted (=internal) SD path by Environment.getExternalStorageDirectory()
.
Now, if I want to get the free Space, something like this:
StatFs statFs = new StatFs(storageDir);
long blocks = statFs.getAvailableBlocks();
return Formatter.formatFileSize(this, blocks * statFs.getBlockSize());
works for internal storage and external SD, but for adopted SD it returns the same value as for internal storage, which is the pure internal storage without the additional SD space.
Now my question is: Is there any way to get the free Space consisting of internal + adopted SD? As far as I can tell, I don't even know if there is an adopted SD present, since getExternalFilesDirs()
always contains the path for /storage/emulated/0
(thats the absolute path for Environment.getExternalStorageDirectory()
for most devices I tested), no matter whether it is mounted or not.
Edit: I ended up just checking if the free space of getExternalStorageDirectory()
is larger than getFilesDir()
+ 100MB since I want to use the adopted SD as alternative storage and I don't need it if there is no free space on it, but that can't be the way it's supposed to work, can it?
来源:https://stackoverflow.com/questions/38117508/android-adoptable-storage-get-free-space