What I'm trying to do in my application is to let the user choose a picture from his phone's gallery. The code I'm using is as follows:
Intent intentBrowseFiles = new Intent();
intentBrowseFiles.setType("image/*");
intentBrowseFiles.setAction(Intent.ACTION_GET_CONTENT);
intentBrowseFiles.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intentBrowseFiles,"Select Picture"), SHOW_GALLERY);
By putting :
intentBrowseFiles.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
I thought this would only fire the gallery intent, but instead user is left with the selection of his drive, dropbox and other online accounts along with the local gallery...
I don't want any other remote resources, is there something that I'm missing here?
When you use an intent action like
ACTION_GET_CONTENT
, you're telling the system to choose which app to open. If the user hasn't set a default for it, it will ask which app to use. The apps in the dialog will show any apps that have said they can handle an intent of that type.If you want to use an intent to start a specific activity, you have to call it by name. The problem here is that the gallery app may be named differently on different devices, or removed altogether.
Allowing a user to choose their app of choice is generally the right thing to do. It's definitely the "Androidy" way to do it.
Either way,
EXTRA_LOCAL_ONLY
only tells the receiving app that it should return only data that is present. It doesn't enforce that condition.