0

I have a problem because on Android 11 I can't send the attachment. The email opens, for example into gmail, but Gmail displays the message couldn't attach file. I read a bunch of posts and instructions for developers, but I didn't find the right solution. ACTION_SENDTO works perfectly on Android 10 and below. Please help, thanks in advance.

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/html");
String message="";
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse( "file://" + filelocation));
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.addFlags(Intent.FLAG_ACTIVITY_REQUIRE_NON_BROWSER);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent, null));

Manifest:

<queries>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="mailto" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent>
</queries>
Dejo
  • 121
  • 1
  • 6
  • You should be crashing with a `FileUriExposedException`. `file://` `Uri` values have been largely banned since Android 7.0. Use `FileProvider` and `getUriForFile()` to get a `Uri` for use with `EXTRA_STREAM`. – CommonsWare May 02 '22 at 22:38

0 Answers0