Android: why Intent.EXTRA_LOCAL_ONLY shows Google Photos

What I'm trying to do in my application is to allow the user to select a picture from their phone gallery (I do not want to receive only gallery images , but also allowing the user to select their choice application). The code I use is as follows:

Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1); 

How Intent.EXTRA_LOCAL_ONLY does not work

EXTRA_LOCAL_ONLY tells only the receiving application that it should return only the data that is present.

After adding intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); in the above code, it hides the Google Drive app and picasa app , but still shows Google photos (these photos are not on my device.)

And I tried the Android picker for local files , but it hides all applications that have deleted images, except for Google photos.

Note: all image paths are correct, as I did Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT (thanks @Paul Burke), but I don’t know if you want to select internet / deleted images.

So my question is, is there a way to hide the Google Photos app when you select only the image from the local device. or Google images are part of Intent.EXTRA_LOCAL_ONLY

+3
source share
1 answer

EXTRA_LOCAL_ONLY tells only the receiving application that it should only return data that is present.

Google+ Photos stores both local and remote snapshots, and because of this, it is fixed with this extra. However, it seems to ignore wherever the called EXTRA_LOCAL_ONLY method EXTRA_LOCAL_ONLY set to true.

You can try removing G + Photos from the list manually (however this seems a bit hacked):

 List<Intent> targets = new ArrayList<Intent>(); Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); List<ResolveInfo> candidates = getPackageManager().queryIntentActivities(intent, 0); for (ResolveInfo candidate : candidates) { String packageName = candidate.activityInfo.packageName; if (!packageName.equals("com.google.android.apps.photos") && !packageName.equals("com.google.android.apps.plus") && !packageName.equals("com.android.documentsui")) { Intent iWantThis = new Intent(); iWantThis.setType("image/*"); iWantThis.setAction(Intent.ACTION_GET_CONTENT); iWantThis.putExtra(Intent.EXTRA_LOCAL_ONLY, true); iWantThis.setPackage(packageName); targets.add(iWantThis); } } Intent chooser = Intent.createChooser(targets.remove(0), "Select Picture"); chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, targets.toArray(new Parcelable[targets.size()])); startActivityForResult(chooser, 1); 

A few words of explanation: targets.remove(0) will remove and return the first Intent from the list of targets , so the selection will consist of only one application. Then, using Intent.EXTRA_INITIAL_INTENTS add the rest.

The code snippet is a modified version of this link .

Do not forget to check all conditions, for example, if at least one application is available, etc.

+8
source

All Articles