Intent.ACTION_OPEN_DOCUMENT_TREE and DocumentsContract.buildChildDocumentsUri do not match

735 views Asked by At

I want to list only files of certain Folder. Im Using Intent.ACTION_OPEN_DOCUMENT_TREE to let the user pick the folder. the URI is safed in sharedPrefs.

Then im trying to get the children from that URI by using

val childrensUriUsingTree = DocumentsContract.buildChildDocumentsUriUsingTree(
            uri,
            DocumentsContract.getTreeDocumentId(uri)
        )

the problem is that the URI childrensUriUsingTree returned by the DocumentsContract does not match the given URI IF the user selected a sub-subfolder. if he uses a 1st level subfolder like Downloads everything works. But if the user selects a sub-subfolder like DCIM/MyFolder that is stripped from the url and only the 1st level subfolder persists.

for instance content://com.android.externalstorage.documents/tree/primary:DCIM/Camera will be made into content://com.android.externalstorage.documents/tree/primary%3ADCIM/document/primary%3ADCIM/children so the Camera part is just stripped.

Which leads to a permission exception because Intent.ACTION_OPEN_DOCUMENT_TREE did not grant access to the 1st level subfolder. Or if permission exists it will list the files from that 1st level subfolder.

Is that a Bug or am i doing something wrong?

0

There are 0 answers