Difference between Intent.ACTION_GET_CONTENT and Intent.ACTION_PICK

JavaAndroidAndroid IntentAndroid Camera-Intent

Java Problem Overview


I'm trying to let the user choose any image that they want on their device to use as a wallpaper in this wallpaper application I'm building. For some reason when I write:

Intent myIntent = new Intent(Intent.ACTION_PICK);
myIntent.setType("image/*");
startActivityForResult(myIntent, 100);

I go straight into the gallery, but when I write:

Intent myIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
myIntent.setType("image/*");
startActivityForResult(myIntent, 100);

I get to choose from Gallery, or Google Drive. What is the best way to let the user choose what app to retrieve the picture from every time? Or why do those two different intent constants make a difference?

Java Solutions


Solution 1 - Java

Your first Intent is invalid. The protocol for ACTION_PICK requires you to supply a Uri indicating the collection you are picking from.

> What is the best way to let the user choose what app to retrieve the picture from every time?

If you want the user to choose something based on MIME type, use ACTION_GET_CONTENT.

If you have some specific collection (identified by a Uri) that you want the user to pick from, use ACTION_PICK.

In case of a tie, go with ACTION_GET_CONTENT. While ACTION_PICK is not formally deprecated, Dianne Hackborn recommends ACTION_GET_CONTENT.

Solution 2 - Java

The modern action is ACTION_GET_CONTENT, which is much better supported,

ACTION_PICK :

Activity Action: Pick an item from the data, returning what was selected.

Input: getData() is URI containing a directory of data (vnd.android.cursor.dir/*) from which to pick an item.

Output: The URI of the item that was picked.

Constant Value: "android.intent.action.PICK"


Difference :-

Activity Action: Allow the user to select a particular kind of data and return it.

This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick.

A ACTION_GET_CONTENT could allow the user to create the data as it runs (for example taking a picture or recording a sound), let them browse over the web and download the desired data, etc.

Reference http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT

Solution 3 - Java

 public static final String ACTION_GET_CONTENT

> > Added in API level 1 > > Activity Action: Allow the user to select a > particular kind of data and return it. This is different than > ACTION_PICK in that here we just say what kind of data is desired, not > a URI of existing data from which the user can pick. A > ACTION_GET_CONTENT could allow the user to create the data as it runs > (for example taking a picture or recording a sound), let them browse > over the web and download the desired data, etc.

via http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEGHDKView Question on Stackoverflow
Solution 1 - JavaCommonsWareView Answer on Stackoverflow
Solution 2 - JavaTarsem SinghView Answer on Stackoverflow
Solution 3 - JavaKevinView Answer on Stackoverflow