Java – How Android gets the name of an app for sharing

How Android gets the name of an app for sharing… here is a solution to the problem.

How Android gets the name of an app for sharing

I’m using the following method to share an image with any app of the user’s choice.

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    File imageFileToShare = new File(imagePath);
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFileToShare));

if (! TextUtils.isEmpty(text)) {
        shareIntent.putExtra(Intent.EXTRA_TEXT, text);
    }
    context.startActivity(Intent.createChooser(shareIntent, "Share with").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

This works fine, but now I’m trying to get the name of the app the user selected for sharing. Is there a (standard) way to do this?

Thanks for the attention.
Jose

Solution

This feature is not supported in versions prior to Android 6.0 when using Android selectors. On Android 6.0+, you can use it EXTRA_ CHOOSER_REFINEMENT_INTENT_SENDER provides an IntentSender that notifies the user when they make a choice and what that choice is.

You are welcome to use PackageManager and queryIntentActivities() to find out which activities support your shareIntent and create your own UI for users to choose from. Then, because it’s your own UI, you’ll find out what the user has chosen.

Related Problems and Solutions