gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 23:05:59 32 4
gpt4 key购买 nike

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

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

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

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

当我使用在

找到的示例代码时

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

并将其放在基本 Activity 应用程序(IDE 创建的示例默认应用程序)中,恰好用户无法选择云存储根目录,只能选择磁盘位置。它在 Kotlin 中,但我将它翻译成 Java 而没有改变它。这不是 Java 问题吗,因为我也尝试了 Kotlin 版本。

[ 我用一些技巧编写了其他代码,这些代码至少会导致在 onActivityResult 方法中返回云文件夹 Uri。它包括使用不同的 Intent 操作,但它仍然不能满足我的目的,中间件不喜欢它所以它中断了 Storage Access Framework - failing to obtain document tree from uri (returned from Drive app) ]

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

<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>

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

最佳答案

DocumentsProvider 可以选择是否支持 ACTION_OPEN_DOCUMENT_TREE 甚至 ACTION_CREATE_DOCUMENT 标志 FLAG_SUPPORTS_IS_CHILDFLAG_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 传递给提供商(在本例中为 Google Drive),提供商最终决定返回哪些文档。由于云端硬盘不支持这样的子关系,因此无法正常工作。

在 Ian Lake 的博文 Building a DocumentsProvider 中有更多详细信息.

关于android - 使用 ACTION_OPEN_DOCUMENT_TREE 时,存储访问框架不显示云根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56539920/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com