And*_*eaF 4 android storage-access-framework android-10.0 android-11
如果我调用 DocumentFile.fromTreeUri()主目录并列出其内容,它会DocumentFile按预期返回与目录中包含的文件夹和文件相关的所有对象,但是当我尝试调用DocumentFile.fromTreeUri()其中Uri的文件夹之一时DocumentFile,而不是返回所有DocumentFile相关对象按预期返回到子目录中包含的文件夹和文件,它实际上返回与其根目录上的调用完全相同的内容Uri
例如,我有一个包含 3 个文件的下载文件夹和一个包含 2 个文件的子文件夹,其结构如下
Download
-->file1
-->file2
-->file3
-->Subfolder
----->subfile1
----->subfile2
Run Code Online (Sandbox Code Playgroud)
如果我调用 通过意图回调选择的DocumentFile.fromTreeUri().listFiles()下载文件夹
它会返回我Uricontent://com.android.externalstorage.documents/tree/primary%3ADownload
-->file1
-->file2
-->file3
-->Subfolder
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都很好,现在如果我尝试获取Uri与调用DocumentFile相关的对象,我得到的显然看起来是正确的,但是如果我调用它,当我列出它的内容时我会再次得到Subfoldermysub.getUri()content://com.android.externalstorage.documents/tree/primary%3ADownload/document/primary%3ADownload%2FSubfolderDocumentFile.fromTreeUri().listFiles()
-->file1
-->file2
-->file3
-->Subfolder
Run Code Online (Sandbox Code Playgroud)
与主下载文件夹 Uri 上的调用完全相同。如果我直接打电话,也会发生同样的情况mysub.listFiles()。这看起来是一个完全不合逻辑的设计。
我怎样才能真正从与其父DocumentFile文件夹相关的对象中正确获取与子文件夹相关的对象DocumentFile,以便子文件夹DocumentFile可以列出其内容而不是其父文件夹的内容?
我也有同样的问题。我升级文档文件版本后解决了这个问题。
implementation 'androidx.documentfile:documentfile:1.0.1'
| 归档时间: |
|
| 查看次数: |
1408 次 |
| 最近记录: |