使用 ACTION_OPEN_DOCUMENT_TREE 时存储访问框架不显示云根

Storage Access Framework doesn't show cloud roots when using ACTION_OPEN_DOCUMENT_TREE

我读到我必须提前为 Android Q 版本准备我的应用程序,因为如果不这样做,那么对应用程序拥有的目录之外的文件的常见 read/write 访问可能会被弃用撤销管理这些文件的新方法。

幸运的是,我没有那么多代码行要更改。

事实上,存储访问框架似乎存在一些问题。它来自 Kitkat,我看到了(我不知道)。否则我的代码是错误的。

我不能简单地让用户在云存储上选择一个文件夹来获取 return 中的 Uri,以进一步填充该文件夹。

当我使用在

找到的示例代码时

https://github.com/android/storage/tree/228c8e0aa19586bfcf36318ddb191719537a45a4/ActionOpenDocumentTree#action_open_document_tree

并把它放在一个基本的 activity 应用程序中(IDE 创建的示例默认应用程序),碰巧用户不能 select 云存储根目录,只能磁盘位置。它在 Kotlin 中,但我将其翻译为 Java 而没有更改。这不是 Java 问题吗,因为我也尝试了 Kotlin 版本。

[ 我用一些技巧编写了其他代码,这些代码至少导致云文件夹 Uri 回到 onActivityResult 方法中。它包括使用不同的意图操作,但它仍然不能满足我的目的,中间件不喜欢它所以它中断了 ]

在这两种情况下我有相同的路径:

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="filesPath" path="/"/>
<external-path name="externalPath" path="/"/>
<external-files-path name="externalFilesPath" path="/"/>
</paths>

如何让用户 select 云提供商上的文件夹以及如何获取 uri?

一个DocumentsProvider可以选择是否支持ACTION_OPEN_DOCUMENT_TREE甚至ACTION_CREATE_DOCUMENT,分别用flagsFLAG_SUPPORTS_IS_CHILD and FLAG_SUPPORTS_CREATE

Google 驱动器目前不支持 ACTION_OPEN_DOCUMENT_TREE,因此无法选择它。

我相信 Nextcloud 支持 ACTION_OPEN_DOCUMENT_TREE,所以这可能会有所帮助。

I wrote other code with some hacks that at least lead to having the cloud folder Uri back in the onActivityResult method. It encompasses using a different intent Action but it still does not serve my purposes, the middleware doesn't like it so it breaks Storage Access Framework - failing to obtain document tree from uri (returned from Drive app)

是的。然后将 URI returned 传递给提供者(在本例中为 Google 驱动器),后者最终决定将哪些文档发送给 return。由于云端硬盘不支持这样的子关系,因此无法正常工作。

Ian Lake 的博客 post Building a DocumentsProvider.

中有更多详细信息