问题
If I call DocumentFile.fromTreeUri()
on main directory and I list its content, it returns all DocumentFile
object related to folders and files contained in the directory as expected, but when I try to call DocumentFile.fromTreeUri()
on the Uri
of one of the DocumentFile
folders inside it, rather than returning all DocumentFile
objects related to folders and files contained in the subdirectory as expected, it actually returns exactly the same content of the call on its root Uri
E.g. I have a Download folder with 3 files and a subfolder with 2 files contained in it structured in this way
Download
-->file1
-->file2
-->file3
-->Subfolder
----->subfile1
----->subfile2
If I call DocumentFile.fromTreeUri().listFiles()
on the Download folder Uri
picked through intent callback content://com.android.externalstorage.documents/tree/primary%3ADownload
It returns me
-->file1
-->file2
-->file3
-->Subfolder
Till now all it's ok, now if I try to get Uri
of DocumentFile
object related to Subfolder
calling mysub.getUri()
I get content://com.android.externalstorage.documents/tree/primary%3ADownload/document/primary%3ADownload%2FSubfolder
that apparently would seem correct, but If I call DocumentFile.fromTreeUri().listFiles()
on it, when I list its content I get again
-->file1
-->file2
-->file3
-->Subfolder
Exactly as the call on the main Download folder Uri. The same happens if I call mysub.listFiles()
directly.
This seems a totally illogical design.
How could I actually get correctly the DocumentFile
objects related to Subfolder from DocumentFile
related to its parent in order that Subfolder DocumentFile
can list its content rather than content of its parent?
来源:https://stackoverflow.com/questions/62375696/unexpected-behavior-when-documentfile-fromtreeuri-is-called-on-uri-of-subdirec