java - Get a DocumentFile that is a child of a document tree without using findFiles() -
i have tree uri got action_open_document_tree, how can documentfile child of tree without using findfiles()? given know how documentid, absolute path or uri. need permissions associated document tree.
this have right now:
documentfile roottree = documentfile.fromtreeuri(context, roottreeuri); documentfile docfile = roottree.findfile(filename); it returns docfile treedocumentfile, child of root. have write permission , can use createfile() on since under document tree action_open_document_tree.
so works findfile() slow.
if try use documentscontract so:
// know how build documentid file's absolute path uri uri = documentscontract.buildtreedocumenturi(roottreeuri.getauthority(), documentid); documentfile docfile = documentfile.fromtreeuri(context, uri); // result: "content://com.android.externalstorage.documents/tree/1a0e-0e2e:mychilddirectory/document/1a0e-0e2e:mychilddirectory" it returns new treedocumentfile rooted @ docfile, not docfile child of original document tree (root). don't have write permission on tree.
and if try so:
uri docuri = documentscontract.builddocumenturiusingtree(roottreeuri, documentid); // result: "content://com.android.externalstorage.documents/tree/1a0e-0e2e:/document/1a0e-0e2e:mychilddirectory" i uri looks want, it's uri, not documentfile.
if same above build documentfile uri fromtreeuri():
uri docuri = documentscontract.builddocumenturiusingtree(roottreeuri, documentid); documentfile docfile = documentfile.fromtreeuri(context, docuri); // result: "content://com.android.externalstorage.documents/tree/1a0e-0e2e:/document/1a0e-0e2e:" i original tree documentfile, not documentfile representing child.
what want not possible current apis. way make treedocumentfile (the private subclass of documentfile supports createfile, createdirectory, listfiles, , renameto) through documentfile.fromtreeuri (which gives root tree uri you've found) or through existing treedocumentfile's listfiles() method, findfile uses internally.
you should file feature request on issuetracker.google.com add new static method need.
Comments
Post a Comment