Unexpected behavior when DocumentFile.fromTreeUri() is called on Uri of subdirectory DocumentFile object

不想你离开。 提交于 2020-06-29 03:42:09

问题


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 Subfoldercalling 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

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