I want to give the user the option to save images on their sd card and I want to be able to calculate the sizes of folders of such images. I find that Environment.getExternalStorageDirectory()
returns internal storage. The only way I can find the sd card is by using an ACTION_OPEN_DOCUMENT_TREE
request. But this means I have to use DocumentFiles rather than regular Files. I can only get a content uri, not a direct path to the sd card itself.
So, File.length()
works well with internal storage but DocumentFile.length()
is extremely slow with external storage. Is there any way to get the size of a folder based on its content uri without it taking forever? Or can I somehow find an actual path to the sd card and use Files instead? I found a folder like /storage/3857-3732
but I don't seem to have permission to write to it (yes I have WRITE_EXTERNAL_STORAGE
permission).