0

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:

enter image description here

Uncommenting it displays:

enter image description here

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?

Community
  • 1
  • 1
RominaV
  • 3,335
  • 1
  • 29
  • 59
  • Wouldn't it be simpler to get rid of all this code and [let the user share where the user wants](https://commonsware.com/blog/2011/06/28/share-where-the-user-wants.html)? – CommonsWare Sep 27 '16 at 12:20
  • @CommonsWare not all developers have the last say on the functionalities of an app. – RominaV Sep 27 '16 at 12:42

0 Answers0