Android:同时支持 ACTION_GET_CONTENT 和 ACTION_OPEN_DOCUMENT 时避免重复输入

标签 android android-intent android-contentprovider android-fileprovider storage-access-framework

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 匹配器(后者显示在分隔线下方)。

是否可以避免应用程序的重复显示以避免用户困惑?

请参阅下面的屏幕截图和显示两次的框条目,了解问题的示例:

Screenshot showing duplicate entry in the Open from dialog

最佳答案

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 support ACTION_GET_CONTENT to accommodate devices that are running Android 4.3 and lower, you should disable the ACTION_GET_CONTENT intent filter in your manifest for devices running Android 4.4 or higher. A document provider and ACTION_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_CONTENTACTION_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/

相关文章:

android - 发布版本中的 ActionBar 缺少后退箭头,但调试版本中没有

android - 在 pjsip 中成功编译 android 后尝试构建 libpjsua2.so 文件时目标不兼容

缺少 Android Intent 参数 FLAG_ACTIVITY_SINGLE_TASK?

java - 如何在待定 Intent 中设置两个 Intent

java - Android - 进度对话框退出操作

android - 异步任务完成后谷歌地图 fragment 更新/刷新

java - 如何从底部导航中删除标题

android - 使用 ContentProvider 插入到多个表

android - 无法使用 Gmail 共享 Assets 中的图像

Android SQLite 数据库和应用更新