Skip to content

TreeDocumentFileCompat.make discards subdirectories if uri is already a document URI #21

@PabloMK7

Description

@PabloMK7

I'm calling DocumentFileCompat.fromTreeUri, with an URI that already has a document: content://com.android.externalstorage.documents/tree/primary:azahar-emu/document/primary:azahar-emu/sdmc, however the code in TreeDocumentFileCompat.make does not check this and tries to build the document URI again. This discards the already built document URI and replaces it with the tree URI, creating: content://com.android.externalstorage.documents/tree/primary:azahar-emu/document/primary:azahar-emu (notice how sdmc part was lost).

A possible solution may be to check if the URI already is a document URI:

val treeUri = if (isInitial && !DocumentsContract.isDocumentUri(context, uri)) {
    DocumentsContract.buildDocumentUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri))
} else {
    uri
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions