Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action send mail to with file Android 11

i have a problem to share a ".zip" file with gmail app or otherwise email sender with Android 11.

Intent email_intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",mailTo, null));
email_intent.putExtra(Intent.EXTRA_SUBJECT, "Log App");
email_intent.putExtra(Intent.EXTRA_TEXT,"");
email_intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID+".provider",new File(log)));
startActivity(Intent.createChooser(email_intent, getString(R.string.invia_tramite)));

I'm not using requestLegacy etc.. but getExternalFilesDir. With lower version of 11 it works.

Please save my day :)

Thanks

like image 683
Lorenzo Sogliani Avatar asked Oct 16 '25 16:10

Lorenzo Sogliani


2 Answers

solved with replacing:

Intent email_intent = new Intent(Intent.ACTION_SEND);
email_intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

and in <manifest> </manifest> putting:

<queries>
    <intent>
        <action android:name="android.intent.action.SEND"/>
        <data android:mimeType="*/*" />
    </intent>
</queries>
like image 120
Lorenzo Sogliani Avatar answered Oct 18 '25 05:10

Lorenzo Sogliani


I found that sending email feedback always fail due to Android 11 restriction illustrated in below link:

Package visibility in Android 11

To resolve this issue, we have to add query to mainfaist file like this:

<queries>
        <!-- Sending Emails   -->
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
</queries>
like image 27
Tamil Arasu Avatar answered Oct 18 '25 07:10

Tamil Arasu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!