私はACTION_OPEN_DOCUMENT_TREE
からもらった木URIを持って、はどのように私はfindFiles()
を使用せずにこの木の子であるDocumentFileを得ることができます取得しますか? documentId、その絶対パスまたはそのURIを取得する方法を知っていることを考えると、私は、ドキュメントツリーに関連付けられているアクセス許可が必要です。FindFilesとを(使用せずに、文書ツリーの子であるDocumentFile)
これは私が今持っているものです。
DocumentFile rootTree = DocumentFile.fromTreeUri(context, rootTreeUri);
DocumentFile docFile = rootTree.findFile(fileName);
それはTreeDocumentFile、私のルートの子としてdocFile
返します。書き込み権限があり、ACTION_OPEN_DOCUMENT_TREE
のドキュメントツリーの下にあるので、createFile()
を使用できます。
だから動作しますが、findFile()
は本当に遅いです。
私はそうのようDocumentsContract使用しようとすると:
// I know how to build the documentId from the 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"
それは私の元のドキュメントツリー(ルート)の子としてdocFile
に根ざした新しいTreeDocumentFile、ないdocFile
を返します。だから私はこの木の書き込み許可を持っていません。
そして、私はそうのようにしようとした場合:
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(rootTreeUri, documentId);
// Result: "content://com.android.externalstorage.documents/tree/1A0E-0E2E:/document/1A0E-0E2E:myChildDirectory"
私はURIを取得し、実際に私が欲しいもののように見えますが、それはURIではなく、DocumentFileです。
私は上記と同じ操作を行うが、fromTreeUri(このURIからDocumentFileを構築する場合):
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(rootTreeUri, documentId);
DocumentFile docFile = DocumentFile.fromTreeUri(context, docUri);
// Result: "content://com.android.externalstorage.documents/tree/1A0E-0E2E:/document/1A0E-0E2E:"
私はDocumentFileが子供を表さない、オリジナルの木のDocumentFileを取得します。
"私は実際に欲しいものに見えるURIを取得しますが、それはDocumentFileではなくURIです" - DocumentFileで 'fromSingleUri()'を使用して 'DocumentFile'にそれをラップします。 – CommonsWare
私はそのように作成された 'DocumentFile'に対する書き込み許可を持っておらず、' createFile() 'を使うことはできません。 – jeanv
それは奇妙です。 AFAIK、あなたは木全体に権利を持っているべきです。そのカバーの下で、 'DocumentFile'はこの種のもののために' DocumentsContract'を使っています - それは 'DocumentFile'が特別なアクセス権を持っているのとは異なります。 – CommonsWare