Using the code from this answer, I'm building an image sharing intent chooser, that should only display a certain set of apps (Instagram, Twitter, Facebook and nothing else).
That works great, but the displaying names of the app are overriden.
With this code:
public static void startImageSharingIntent(Activity caller, List<String> possiblePackagesNames, Uri imgUri) {
try {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent intentTemplate = new Intent(Intent.ACTION_SEND);
intentTemplate.setType("image/*");
List<ResolveInfo> resInfo = caller.getPackageManager().queryIntentActivities(intentTemplate, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (possiblePackagesNames.contains(info.activityInfo.packageName.toLowerCase())) {
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
targetedShare.setType("image/*");
targetedShare.putExtra(Intent.EXTRA_STREAM, imgUri);
targetedShare.setPackage(info.activityInfo.packageName);
//adding bottom line puts the app name in the intent
targetedShare.setClassName(info.activityInfo.packageName, info.activityInfo.name);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
caller.startActivity(chooserIntent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
If I comment the line targetedShare.setClassName(info.activityInfo.packageName, info.activityInfo.name);
, this is the resulting chooser:
Uncommenting it displays:
In the first one it displays an "Android system" option, which is wrong; but in the second one the label for different actions of Twitter are renamed to Twitter only.
Is there a way to avoid the "Android system" option but not overriding the default intent name?