http://developer.android.com/guide/topics/providers/document-provider.html状态:
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:
Use ACTION_GET_CONTENT if you want your app to simply read/import data.
With this approach, the app imports a copy of the data, such as an image file.
Use ACTION_OPEN_DOCUMENT if you want your app to have long term, persistent access
to documents owned by a document provider. An example would be a
photo-editing app that lets users edit images stored in a document provider.
这表明大多数提供文件的应用程序应该支持这两种 Intent 类型。
但是,当应用同时支持 ACTION_GET_CONTENT
(通过在其 Intent 过滤器中具有与其匹配的 Activity )和 ACTION_OPEN_DOCUMENT
(通过实现文档提供程序)时,它会显示两次当例如将文件附加到 Gmail。这是因为文件选取 UI 显示了文档提供程序和 ACTION_GET_CONTENT
匹配器(后者显示在分隔线下方)。
是否可以避免应用程序的重复显示以避免用户困惑?
请参阅下面的屏幕截图和显示两次的框条目,了解问题的示例:
最佳答案
从 Supporting devices running Android 4.3 and lower section 中同一页面稍远的位置开始:
The
ACTION_OPEN_DOCUMENT
intent is only available on devices running Android 4.4 and higher. If you want your application to supportACTION_GET_CONTENT
to accommodate devices that are running Android 4.3 and lower, you should disable theACTION_GET_CONTENT
intent filter in your manifest for devices running Android 4.4 or higher. A document provider andACTION_GET_CONTENT
should be considered mutually exclusive. If you support both of them simultaneously, your app will appear twice in the system picker UI, offering two different ways of accessing your stored data. This would be confusing for users.
您引用的部分位于客户端 - 连接到您的DocumentsProvider
的应用可以使用ACTION_GET_CONTENT
和ACTION_OPEN_DOCUMENT
,因此您在 Android 4.4 及更高版本的设备上不再需要 ACTION_GET_CONTENT
Intent 过滤器或 Activity。
他们建议根据版本代码(即在 values-v19
中)创建 bool
资源,这将允许您更改 android:enabled
Manifest 中的值,根据 Android 版本禁用或启用组件。
关于Android:同时支持 ACTION_GET_CONTENT 和 ACTION_OPEN_DOCUMENT 时避免重复输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36782844/