ACTION_GET_CONTENT和ACTION_OPEN_DOCUMENT之间的真正区别是什么? [英] What is the real difference between ACTION_GET_CONTENT and ACTION_OPEN_DOCUMENT?

查看:300
本文介绍了ACTION_GET_CONTENT和ACTION_OPEN_DOCUMENT之间的真正区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解 ACTION_OPEN_DOCUMENT ACTION_GET_CONTENT 意向在用于打开可打开文档时的区别.如果我在KitKat之前支持Andriod,而KitKat不支持 ACTION_OPEN_DOCUMENT ,我是否应该解决 ACTION_GET_CONTENT ?

I'm having a hard time understanding the difference between ACTION_OPEN_DOCUMENT and ACTION_GET_CONTENT intents when they are used to open an openable document. If I am supporting Andriod before KitKat, which does not support ACTION_OPEN_DOCUMENT, should I just settle with ACTION_GET_CONTENT?

文档表示:

ACTION_OPEN_DOCUMENT 不是旨在替代 ACTION_GET_CONTENT .您应该使用哪种取决于您的需求您的应用程序:

ACTION_OPEN_DOCUMENT is not intended to be a replacement for ACTION_GET_CONTENT. The one you should use depends on the needs of your app:

  • 如果使用 ACTION_GET_CONTENT 您希望您的应用程序简单地读取/导入数据.通过这种方法,应用可以导入数据的副本,例如图片文件.
  • 如果使用 ACTION_OPEN_DOCUMENT 您希望您的应用具有长期,持久地访问文档所拥有的文档提供者.一个示例就是可以让用户进行编辑的照片编辑应用程序存储在文档提供程序中的图像.

ACTION_GET_CONTENT 是否也使用KitKat中的文档提供程序?是什么使我无法进行长期的,持续的访问",这到底是什么意思?

Doesn't ACTION_GET_CONTENT also use document providers in KitKat? What would prevent me from having "long term, persistent access" and what exactly does that mean?

基本上,以下两个代码段之间有什么区别?

Basically, what is the difference between the following two snippets?

ACTION_GET_CONTENT

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");

ACTION_OPEN_DOCUMENT

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");

推荐答案

ACTION_GET_CONTENT也不在KitKat中使用文档提供程序吗?

Doesn't ACTION_GET_CONTENT also use document providers in KitKat?

不一定.这取决于发布内容的应用程序的实现.还要注意, DocumentProvider ContentProvider 的特定类型.

Not necessarily. That depends on the implementation of the app that is publishing the content. Also note that DocumentProvider is a specific type of ContentProvider.

是什么使我无法长期,持久地访问"

What would prevent me from having "long term, persistent access"

ACTION_GET_CONTENT 取回的 Uri 可能具有与您的应用程序相关的临时权限授予,以便能够读取和/或写入内容.该授予最终将失效(例如,当您的进程终止时).因此,例如,将 Uri 保存为数据库中的字符串可能毫无意义.

The Uri that you get back from ACTION_GET_CONTENT may have a temporary permission grant with it for your app, to be able to read and/or write the content. That grant will eventually lapse (e.g., when your process terminates). So, for example, saving the Uri as a string in a database may be pointless.

存储访问框架的一部分包括以下概念:内容提供者可以提供可以持续较长时间(长期,持久")的许可.虽然并没有阻止应用程序在API级别19+上通过 ACTION_GET_CONTENT 提供此类持久权限的功能,但在 ACTION_OPEN_DOCUMENT 上,它们将更为常见.

Part of the Storage Access Framework includes the concept that a provider of content can offer permission grants that can last for an extended period ("long-term, persistent"). While there's nothing stopping an app from offering such persistent permissions with ACTION_GET_CONTENT on API Level 19+, they will be more common with ACTION_OPEN_DOCUMENT.

基本上,以下两个代码段之间有什么区别?

Basically, what is the difference between the following two snippets?

用户体验会有所不同,因为 ACTION_OPEN_DOCUMENT 提供了标准化的文件浏览器样式的界面,而 ACTION_GET_CONTENT 是传统的选择器对话框,其后是一些特定于应用程序的对话框用户界面.

The user experience will be somewhat different, as ACTION_OPEN_DOCUMENT provides a standardized file explorer-style interface, whereas ACTION_GET_CONTENT is a traditional chooser dialog, followed by some app-specific UI.

从您作为该内容的使用者的角度来看, ACTION_GET_CONTENT 是您现在要使用该内容;如果您要立即使用该内容,则为

ACTION_GET_CONTENT . ACTION_OPEN_DOCUMENT 是如果您想现在和以后使用这些内容.

From your standpoint as a consumer of this content, ACTION_GET_CONTENT is if you want to use the content now; ACTION_OPEN_DOCUMENT is if you want to use the content now and later.

指向文档的链接:

ACTION_OPEN_DOCUMENT

ACTION_GET_CONTENT

来自用于打开特定类型文件的通用意图示例:

在Android 4.4或更高版本上运行时,您可以请求打开由另一个应用程序管理的文件,而无需检索必须导入到应用程序中的文件的副本(通过使用ACTION_GET_CONTENT操作).ACTION_OPEN_DOCUMENT操作并指定MIME类型.要还允许用户创建您的应用程序可以写入的新文档,请改用ACTION_CREATE_DOCUMENT操作.例如,ACTION_CREATE_DOCUMENT意向允许用户选择要创建新文档的位置(在另一个管理该文档存储的应用程序中),而不是从现有的PDF文档中进行选择-然后,您的应用程序将接收它可以在何处创建的URI位置.编写新文档.

Instead of retrieving a copy of a file that you must import to your app (by using the ACTION_GET_CONTENT action), when running on Android 4.4 or higher, you can instead request to open a file that's managed by another app by using the ACTION_OPEN_DOCUMENT action and specifying a MIME type. To also allow the user to instead create a new document that your app can write to, use the ACTION_CREATE_DOCUMENT action instead. For example, instead of selecting from existing PDF documents, the ACTION_CREATE_DOCUMENT intent allows users to select where they'd like to create a new document (within another app that manages the document's storage)—your app then receives the URI location of where it can write the new document.

尽管从ACTION_GET_CONTENT操作传递到onActivityResult()方法的意图可以返回任何类型的URI,但是ACTION_OPEN_DOCUMENT和ACTION_CREATE_DOCUMENT的结果意图始终将所选文件指定为内容:由DocumentsProvider支持的URI.您可以使用openFileDescriptor()打开文件,并使用DocumentsContract.Document中的列查询其详细信息.

Whereas the intent delivered to your onActivityResult() method from the ACTION_GET_CONTENT action may return a URI of any type, the result intent from ACTION_OPEN_DOCUMENT and ACTION_CREATE_DOCUMENT always specify the chosen file as a content: URI that's backed by a DocumentsProvider. You can open the file with openFileDescriptor() and query its details using columns from DocumentsContract.Document.

这篇关于ACTION_GET_CONTENT和ACTION_OPEN_DOCUMENT之间的真正区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆