android - Get File Uri from Document Id in Storage Access Framework -


i using directory selection described in google sample. provide file name , mime type of children of selected directory. can document id of file too, if use column_document_id on cursor query. interested in file uri of children instead. when use action_open_document instead of action_open_document_tree, child uri obtained adding %2fchildfile.extention (%2f forward slash). tried child file uri using following code -

uri = uri.parse(docuri.tostring()+"%2f"+filename); 

i got file name, when run exists() method on (by converting documentfile), returns false. means, either don't have permission of file or it's not correct way children uri.

am missing here or there other way can select folder , file uri of of it's children easily.

ps: checking in marshamallow.

after reading doc , trying out examples, got following way single file uri selected docuri/treeuri

uri = documentscontract.builddocumenturiusingtree(docuri,docid); 

and can convert anytime documentfile using following code -

documentfile file = null; if (build.version.sdk_int >= build.version_codes.kitkat) {    if (documentscontract.isdocumenturi(context, uri)) {        file = documentfile.fromsingleuri(context, uri);    } else {        file = documentfile.fromtreeuri(context, uri);    } } 

fromtreeuri() method required selected tree directory, can return true on file.exists() method call.
need remember if children contain directory, can't call childdirectory.listfiles() on it. it'll give unsupportedoperationexception, because don't have permission access child directory's file. read more here.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -