I am attaching a TEXT file to Email with code :
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
"[email protected]", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, prepareBodyMail());
File root = Environment.getExternalStorageDirectory();
File file = new File(root, "/MyFolder/report.txt");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));
This code works perfectly with Gmail, Email and other apps
But this is not attaching file with INBOX application by Google
Only Body and subject are coming without any attachment
I have reported this problem to Google Groups at Inbox Problem
Can anybody help what I am missing in code?
In Kotlin
fun Context.shareAttachmentsToMail(mailId: String?, uri: Uri, subject: String, bodyMessage: String){
val selectorIntent = Intent(ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
}
val emailIntent = Intent(ACTION_SEND).apply {
putExtra(Intent.EXTRA_EMAIL, arrayOf(mailId))
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_TEXT, bodyMsg)
putExtra(Intent.EXTRA_STREAM, uri)
selector = selectorIntent
}
try {
startActivity(Intent.createChooser(emailIntent, ""))
} catch (e: ActivityNotFoundException) {
// Application not found
}
}
Call this extension function like this:
requireContext().shareAttachmentsToMail(mailId = mailId, uri = uri, subject = "your subject", bodyMessage = "your body message")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With