0

I'm using this code to share content ( Image from URL and text ). but this is not working properly. I'm getting no error, but it's not sharing (I'm trying to share in WhatsApp and GoogleDrive).

  Uri imageUri = Uri.parse("http://2805messa.8.2.f.unblog.fr/files/2008/03/elmahdia.jpg");


                    Intent intent = new Intent(Intent.ACTION_SEND);

                    intent.putExtra(Intent.EXTRA_TEXT, post.getPost_text());
                    intent.putExtra(Intent.EXTRA_STREAM, imageUri);
                    intent.setType("image/jpeg");
                    v.getContext().startActivity(intent);

I've already seen the other related posts, but I couldn't find an answer to my question.

Stranger B.
  • 9,004
  • 21
  • 71
  • 108

1 Answers1

1

Add the flag : FLAG_GRANT_READ_URI_PERMISSION. Also check for internet permissions.

Modified code:

Uri imageUri = Uri.parse(path);

                Intent intent = new Intent(Intent.ACTION_SEND);

                intent.putExtra(Intent.EXTRA_TEXT, post.getPost_text());
                intent.putExtra(Intent.EXTRA_STREAM, imageUri);
                intent.setType("image/jpeg");
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                v.getContext().startActivity(intent);