Use ACTION_SEND
:
val intent = Intent(Intent.ACTION_SEND).apply {
// The intent does not have a URI, so declare the "text/plain" MIME type
type = "text/plain"
putExtra(Intent.EXTRA_EMAIL, arrayOf("jan@example.com")) // recipients
putExtra(Intent.EXTRA_SUBJECT, "Email subject")
putExtra(Intent.EXTRA_TEXT, "Email message text")
}
startActivity(intent)
https://developer.android.com/training/basics/intents/sending
Also your original code has:
startActivity(intent)
startActivity(Intent.createChooser(intent, "Open E-mail")
Drop the duplication
Don't forget to account for the scenario where zero app's match your intent:
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
// Define what your app should do if no activity can handle the intent.
}
If the system identifies more than one activity that can handle the intent, it displays a dialog (sometimes referred to as the "disambiguation dialog") for the user to select which app to use. If there is only one activity that handles the intent, the system immediately starts it.
createChooser
is for when you want the user to potentially select a different app each time. For example when sharing an image, perhaps one time they want to use Signal and another time WhatsApp or Twitter.