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?
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 .
If you have to pick a file in your app, but you don't want to implement your own file explorer; you can start a activity with intent of Intent. ACTION_GET_CONTENT. Android OS will choice a suitable app with such function for you.
ACTION_PICK action is in buit in android and helps to pick an image item from a data source. We just need to provide the URI of the provider. Almost all core android applications (eg. Messaging, Gallery, Contacts etc) provide this facility. All you need is to set the intent action and the data.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With