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
?
The documentation says this:
ACTION_OPEN_DOCUMENT
is not intended to be a replacement forACTION_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.
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("*/*");
Not necessarily. That depends on the implementation of the app that is publishing the content. Also note that
DocumentProvider
is a specific type ofContentProvider
.The
Uri
that you get back fromACTION_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 theUri
as a string in a database may be pointless.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 withACTION_OPEN_DOCUMENT
.The user experience will be somewhat different, as
ACTION_OPEN_DOCUMENT
provides a standardized file explorer-style interface, whereasACTION_GET_CONTENT
is a traditional chooser dialog, followed by some app-specific UI.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.Edit: Links to documentation:
ACTION_OPEN_DOCUMENT
ACTION_GET_CONTENT
From the Common Intents example for opening a specific type of file: