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?
via http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
Your first
Intent
is invalid. The protocol forACTION_PICK
requires you to supply aUri
indicating the collection you are picking from.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, useACTION_PICK
.In case of a tie, go with
ACTION_GET_CONTENT
. WhileACTION_PICK
is not formally deprecated, Dianne Hackborn recommendsACTION_GET_CONTENT
.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