Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Android email redirect is not working as expected

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);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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@email.com"))
            putExtra(Intent.EXTRA_SUBJECT, "subject")
            putExtra(Intent.EXTRA_TEXT, "body")
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading