Home > Software engineering >  Android email redirect is not working as expected
Android email redirect is not working as expected

Time:06-09

I want to make a button where on click the user to be redirected to email with exact email set as recipient, but this function is not working, in contrast the subject field is working

@Composable
fun sendEmail(emailIds: Array<String> =  arrayOf("Some email")) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.setData(Uri.parse("mailto:"))
intent.putExtra(Intent.EXTRA_TEXT, emailIds);
intent.putExtra(Intent.EXTRA_SUBJECT, "somesubject")
val context = LocalContext.current
Button(onClick = {
    startActivity(context, intent, null) }
) {
    Text("BUTTON")
} 
 }

this line is not working intent.putExtra(Intent.EXTRA_TEXT, emailIds);

CodePudding user response:

Add Intent.EXTRA_EMAIL with an array of recipients

val emailIntent = Intent(Intent.ACTION_SENDTO).apply {
            data = Uri.parse("mailto:")
            putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
            putExtra(Intent.EXTRA_SUBJECT, "subject")
            putExtra(Intent.EXTRA_TEXT, "body")
        }
  • Related