1

I am trying to share image and text via SMS. I am adding the image Uri but Image is not attached with SMS. What is wrong with my code please tell me Advance Thanks.

`Intent share = new Intent(Intent.ACTION_VIEW);
            share.setType("image/png");
            share.setData(Uri.parse("sms:"));
            share.putExtra(Intent.EXTRA_SUBJECT, subject);
            share.putExtra(Intent.EXTRA_TEXT, text);
            Uri uri=FileProvider.getUriForFile(getActivity(),getApplicationContext().getPackageName() + ".provider",file);
            share.putExtra(Intent.EXTRA_STREAM, uri);
            startActivity(share);
  • 3
    `Uri.fromFile()` results in a `Uri` that has a `file` scheme. That has been banned (for the most part) since Android 7.0. Use `FileProvider` to serve up your content, and use `FileProvider.getUriForFile()` to populate your `EXTRA_STREAM` extra. Also, use a concrete MIME type, not a wildcard. And, bear in mind that there is no requirement for any SMS client to support `ACTION_VIEW` with an otherwise-empty `sms:` `Uri`. – CommonsWare Oct 10 '19 at 11:06
  • 1
    Here is [the documentation for sending an SMS via an `Intent`](https://developer.android.com/guide/components/intents-common#SendMessage). – CommonsWare Oct 10 '19 at 11:07
  • This does not solve my problem – HusnainMohsin Oct 10 '19 at 11:23
  • 1
    You might consider editing your question and providing the revised source code, in case we spot problems with your new implementation. – CommonsWare Oct 10 '19 at 11:39
  • My image is in sdcard and file provider does not support removable storage. – HusnainMohsin Oct 10 '19 at 11:44
  • Use the Storage Access Framework to allow the user to choose your content, then use the `Uri` that you get back in your `EXTRA_STREAM` value. Bear in mind that you have limited access to removable storage on Android 4.4+, and you have almost no access to removable storage on Android 10+. – CommonsWare Oct 10 '19 at 11:45
  • I edit the code here is the thing but result is same Image is not attaching to sms. – HusnainMohsin Oct 10 '19 at 12:29

0 Answers0