Android Adoptable Storage - get free Space

情到浓时终转凉″ 提交于 2019-12-10 09:31:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!