Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to get name of app used to share

I'm using the following method to share an image with any app the user picks.

    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 picked by the user for sharing. Is there a (standard) way to do this?

Thanks for the attention. Jose

like image 676
Jose Gonzalez Avatar asked Mar 12 '23 03:03

Jose Gonzalez


1 Answers

This is not supported prior to Android 6.0, when using the Android chooser. On Android 6.0+, you can use EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER to provide an IntentSender that will be notified when the user makes a choice and what that choice is.

You are welcome to use PackageManager and queryIntentActivities() to find out what activities support your shareIntent and create your own UI for the user to choose from. Then, since it is your own UI, you will find out what the user chose.

like image 82
CommonsWare Avatar answered Mar 20 '23 19:03

CommonsWare