Target application detection when sending intent

I am using an image using the send intent (ACTION_SEND).

I want to know if any application is selected for sharing or not. How can I do this and how do I know if an image was sent successfully?

The code I used to share the image is here:

Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(imageSharePath))); startActivity(Intent.createChooser(share, "Share Image")); 
+4
source share
1 answer

You need to implement your own dialogue to select activity.

To create such dialogs, you need to use PackageManager.queryIntentActivities() . This method returns a List<ResolveInfo> .

ResolveInfo contains some information about the activity (for example, resolveInfo.activityInfo.packageName ), and using PackageManager you can get other information (useful for displaying activity in the dialog box) - application shortcut, application shortcut, etc.

Display the results in a list in a dialog box (or as an action as a dialog). When the item is clicked, create a new Intent.ACTION_SEND , add the desired content and add the package of the selected intent.setPackage(pkgName) .

+11
source

All Articles