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

Android: Avoid duplicate entry when supporting both ACTION_GET_CONTENT and ACTION_OPEN_DOCUMENT

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.

这表明大多数提供文件的应用程序都应该支持这两种意图类型。

但是当应用程序同时支持 ACTION_GET_CONTENT(通过在其 intent 过滤器中匹配 activity)和 ACTION_OPEN_DOCUMENT(通过实施文档提供程序)时,它会显示两次当例如将文件附加到 Gmail。这是由于文件选择 UI 同时显示了文档提供程序和 ACTION_GET_CONTENT 匹配器(后者显示在分隔线下方)。

是否可以避免重复显示应用程序以避免混淆用户?

有关问题的示例,请参见下面的屏幕截图和出现两次的 Box 条目:

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,所以你不再需要 ACTION_GET_CONTENT intent-filter 或 activity 在 Android 4.4 和更高版本的设备上。

他们建议根据版本代码(即在 values-v19 中)创建 bool 资源,这将允许您更改清单中的 android:enabled 值,禁用或启用基于组件在 Android 版本上。