Lorenzo Sogliani
Lorenzo Sogliani

Reputation: 227

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

Upvotes: 4

Views: 4153

Answers (2)

Lorenzo Sogliani
Lorenzo Sogliani

Reputation: 227

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>

Upvotes: 11

Tamil Arasu
Tamil Arasu

Reputation: 111

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>

Upvotes: 6

Related Questions