0

I want to view and share an image with 2 Intents, this is my code:

Intent IntentView = new Intent(Intent.ACTION_VIEW);
IntentView.setDataAndType(Uri.fromFile(imageFile), "image/jpg");

Intent IntentShare = new Intent(Intent.ACTION_SEND);
IntentShare.setType("image/jpg");
IntentShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
IntentShare.createChooser(IntentShare, "Share with:");

Intent[] TwoIntents = {IntentView, IntentShare};

CurrentActivity.startActivities(TwoIntents);

"CurrentActivity" comes as an argument to the method and "imageFile" is a File object.

Unfortunately the image does not show it, only the chooser appears and until the sharing activity is finished, the image appears.

How can I do it?

Thank you very much for your help.

Regards!

  • What does "I want to view and share an image with 2 Intents" mean? By default, only one activity is shown at a time. Also, note that `Uri.fromFile()` will fail on Android 7.0+ devices, triggering a `FileUriExposedException`. – CommonsWare Jan 15 '19 at 17:52
  • Hello @CommonsWare, thanks for your comment. I want to open an existing image file in the gallery and after opening it, show the typical sharing menu. Thanks for comment about Uri.fromFile() I will try to use the solution described here: https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed – Francisco Alcibar Jan 15 '19 at 18:04
  • What is "the typical sharing menu?". If you mean some sort of share option in whatever activity appears from `ACTION_VIEW`, that is not possible. If you mean your own `ACTION_SEND`, then what is the point of the `ACTION_VIEW`, if you plan on immediately replacing it with `ACTION_SEND`? – CommonsWare Jan 15 '19 at 18:06

0 Answers0