fornwall
fornwall

Reputation: 2917

Android: Avoid duplicate entry when supporting both ACTION_GET_CONTENT and ACTION_OPEN_DOCUMENT

http://developer.android.com/guide/topics/providers/document-provider.html states:

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.

This indicates that most apps that provides files should support both intent types.

But when an app supports both ACTION_GET_CONTENT (by having an activity matching that in its intent filter) and ACTION_OPEN_DOCUMENT (by implementing a document provider), it is shown twice when e.g. attaching a a file to Gmail. This is due to the file picking UI showing both document providers and ACTION_GET_CONTENT matchers (the latter being shown further down below a divider).

Is it possible to avoid this duplicate showing of an app to avoid confusing users?

See the below screenshot and the Box entry showing up twice for an example of the problem:

Screenshot showing duplicate entry in the Open from dialog

Upvotes: 2

Views: 393

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199880

From slightly farther down on that same page in the 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.

The section you refer to is on the client side - apps connecting to your DocumentsProvider can use both ACTION_GET_CONTENT and ACTION_OPEN_DOCUMENT, so you no longer need the ACTION_GET_CONTENT intent-filter or activity at all on Android 4.4 and higher devices.

They suggest creating bool resources based on version code (i.e., in values-v19) that would allow you to change the android:enabled value in the Manifest, disabling or enabling components based on Android version.

Upvotes: 2

Related Questions