Thursday 18 March 2021

couldn't attach file send email android 11

I am developing an application that sends processing reports via email. When completing the processing data in the application, the user sends an email containing the processing data. However, I am facing a problem on Android 11. When attaching the report to the email, regardless of the email application, a message appears: the file could not be attached. I've been researching a little and saw that it may be related to the permission to access the internal storage of the device on devices with version of android 11. I would like me to help you send email with file attached on android 11.

My code: Manifest

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:requestLegacyExternalStorage="true"
    tools:ignore="AllowBackup"
    tools:targetApi="n">

    <activity.....

Class send email:

val mIntent = Intent(Intent.ACTION_SENDTO)
            mIntent.data = Uri.parse("mailto:");
            mIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("test@gmail.com"))
            mIntent.putExtra(Intent.EXTRA_SUBJECT, EMAIL_SUBJECT)
            mIntent.putExtra(
                Intent.EXTRA_TEXT,
                "Benchmark"
            )
            mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            mIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://$mFilePathDaily"))
            val mailer = Intent.createChooser(mIntent, null)
           
            progressDialog.dismiss()
            activity.startActivityForResult(Intent.createChooser(mailer, ""), 800);


from couldn't attach file send email android 11

No comments:

Post a Comment