AndreaF
AndreaF

Reputation: 12375

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

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?

Upvotes: 5

Views: 1662

Answers (1)

sowhat
sowhat

Reputation: 161

I have the same problem. I solved it after upgrading the documentfile version.

implementation 'androidx.documentfile:documentfile:1.0.1'

Upvotes: 10

Related Questions