4

I am sharing image by using the send intent(ACTION_SEND).

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

Code I have used to share 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"));
Anchit Mittal
  • 3,412
  • 4
  • 28
  • 48
Zankhna
  • 4,570
  • 9
  • 62
  • 103
  • what do u meant by this? "i want to know if any application is selected for sharing or not." – Tamilselvan Kalimuthu Sep 19 '13 at 12:37
  • he want to know which app is selected - share a picture via facebook, twitter, bluetooth etc. – mihail Sep 19 '13 at 12:39
  • This code opens dialog with application list which allows us to share image. and then we select application like whats app , facebook etc. but how can we know that any application is selected for sharing or not. – Zankhna Sep 19 '13 at 12:39

2 Answers2

11

You need to implement your own dialog for the activity selection.

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

ResolveInfo contains some information about an activity (e.g. resolveInfo.activityInfo.packageName), and with the help of PackageManager you can get other information (useful for displaying the activity in the dialog) - application icon drawable, application label, etc.

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

Chilledrat
  • 2,593
  • 3
  • 28
  • 38
Anchit Mittal
  • 3,412
  • 4
  • 28
  • 48
1

The answer above is no longer correct.

Since API 22 it is possible to detect the target application when the user shares.

For details see:

Get IntentSender object for createChooser method in Android

https://medium.com/code-with-lisa/get-results-from-android-chooser-9cfc5445a871

Frank Harper
  • 3,027
  • 3
  • 30
  • 41
  • The medium link was super helpful. One small error in her post... in you need to use the fully qualified name to the BroadcastReceiver in your AndroidManifest, not just the class name (i.e. com.mycompany.packagename.MyBroadcastReceiver) – Diarrhio Apr 15 '20 at 08:56