I\'m using Intent.ACTION_SEND to send an email. However, when I call the intent it is showing choices to send a message, send an email, and also to
Shout-out to ARLabs for posting the best solution on how to send an email on android. I just made a little update - an option to add multiple email attachements.
fun sendEmail(context: Context, recipients: List?, subject: String?, body: String?, attachments: List?) {
val emailIntent = Intent(Intent.ACTION_SEND_MULTIPLE)
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
emailIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
emailIntent.selector = Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"))
if (recipients != null) {
val recipientsArray = arrayOfNulls(recipients.size)
ArrayList(recipients).toArray(recipientsArray)
emailIntent.putExtra(Intent.EXTRA_EMAIL, recipientsArray)
}
if (subject != null) {
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
}
if (body != null) {
emailIntent.putExtra(Intent.EXTRA_TEXT, body)
}
if (attachments?.isNotEmpty() == true) {
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(attachments))
}
if (emailIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(emailIntent)
}
}