I am trying to display multiple options including that of camera, etc to end-user to pick (or click) a photo to set to a profile. Problem is, the chooser intent has multiple intents including google photos, one drive, files, etc but it's showing first three intents only.
Below is my code:
List < Intent > allIntents = new ArrayList < Intent > ();
PackageManager packageManager = context.getPackageManager();
// Fetch all camera related intents
Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
List < ResolveInfo > camList = packageManager.queryIntentActivities(openCamera, 0);
for (ResolveInfo resolveInfo: camList) {
Intent intent = new Intent(openCamera);
intent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
intent.setPackage(resolveInfo.activityInfo.packageName);
if (imageURI != null)
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageURI);
allIntents.add(intent);
}
// Fetch all gallery related intents
Intent openGallery = new Intent(Intent.ACTION_GET_CONTENT);
openGallery.setType("image/*");
List < ResolveInfo > galList = packageManager.queryIntentActivities(openGallery, 0);
for (ResolveInfo resolveInfo: galList) {
Intent intent = new Intent(openGallery);
intent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
intent.setPackage(resolveInfo.activityInfo.packageName);
allIntents.add(intent);
}
Intent deletePhoto = new Intent("com.my_package.intent.action.DELETE_PHOTO");
List < ResolveInfo > delList = packageManager.queryIntentActivities(deletePhoto, 0);
for (ResolveInfo resolveInfo: delList) {
Intent intent = new Intent(deletePhoto);
intent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name));
intent.setPackage(resolveInfo.activityInfo.packageName);
allIntents.add(intent);
}
// Main intent
Intent mainIntent = allIntents.get(allIntents.size() - 1);
// Create a chooser
Intent chooserIntent = Intent.createChooser(mainIntent, "Select source of the photo");
// Add other intents now
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()]));
return chooserIntent;
I have added intent-filter to my AndroidManifest.xml as well:
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
<intent>
<action android:name="com.my_package.intent.action.DELETE_PHOTO" />
</intent>
<intent>
<action android:name="android.intent.action.GET_CONTENT" />
<data android:mimeType="image/*" />
</intent>
</queries>
The code works fine as expected in Android API 28 (ie. displays all the image related intents), but not in API 29+.
The chooserIntent does have extra values of multiple intents which are supposed to be displayed, it's just not displaying them.
question from:
https://stackoverflow.com/questions/65914030/android-custom-chooser-intent-shows-three-options-only 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…