Android: Sending E-mail with attachment through Share Intent

Sree Kumar A.V
1 min readMar 1, 2019

--

Share intent is pretty easy to share contents with other apps. But it works pretty well if you sent the proper MIME type. Things get messy if you want to share an attachment with e-mail client installed in the device.

Unfortunately, the ACTION_SENDTO Intent doesn’t support attachments. You have to choose Intent.ACTION_SEND.

/**
* E-mail intent for sending attachment
*/
private fun sendEmail() {
LogUtils.d(TAG, "Sending Log ...###### ")
val emailIntent: Intent = Intent(Intent.ACTION_SEND)
emailIntent.type = "message/rfc822"
emailIntent.putExtra(Intent.EXTRA_SUBJECT, SUBJECT_EMAIL)
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(SUPPORT_EMAIL))
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
emailIntent.putExtra(Intent.EXTRA_TEXT, BODY_EMAIL)
try {
context?.startActivity(Intent.createChooser(emailIntent, INTENT_CHOOSER_MESSAGE))
} catch (ex: ActivityNotFoundException) {
LogUtils.d(TAG, "No Intent matcher found")
}

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sree Kumar A.V
Sree Kumar A.V

Written by Sree Kumar A.V

Lead Android Software Engineer @ YML

No responses yet

Write a response