Intent.EXTRA_EMAIL no completa el campo Para

Estoy tratando de usar un to send an email from my application but the To field of the email will not populate. If I add code to fill in the subject or text, they work fine. Just the To field will not populate.

I have also tried changing the type to "text/plain" and "text/html" but I get the same problem. Can anyone help please?

public void Email(){

    Intent emailIntent = new Intent(Intent.ACTION_SEND); 
    emailIntent.setType("message/rfc822");  //set the email recipient
    String recipient = getString(R.string.IntegralEmailAddress);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL  , recipient);
    //let the user choose what email client to use
    startActivity(Intent.createChooser(emailIntent, "Send mail using...")); }

The email client I'm trying to use is Gmail

preguntado el 01 de febrero de 12 a las 14:02

7 Respuestas

I think you are not passing recipient as array of string

debería ser como

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "someone@gmail.com" });

Respondido el 02 de junio de 16 a las 19:06

Android... why are you so pathetic? - Suceden errores

hahaha, you made me laugh +1 Million @BugsHappen .. Reasons : Its a open source but documentation are not 100% satisfactory,device manufacturers modify according their needs(most devices are cheap and useless), developers doesn't read "developer.android.com". - MKJParekh

Also make sure that you are NO "Hacer" intent.putExtra(Intent.EXTRA_EMAIL, list.toArray()) it WON'T WORK since list.toArray() produces Object[] and not String[] - nikib3ro

@kape123 this does work however intent.putExtra(Intent.EXTRA_EMAIL, list.toArray(new String[0])) - Abtin Gramian

Utilizar este

public void Email(){
    // use this to declare your 'recipient' string and get your email recipient from your string xml file
    Resources res = getResources();
    String recipient = getString(R.string.IntegralEmailAddress);
    Intent emailIntent = new Intent(Intent.ACTION_SEND); 
    emailIntent.setType("message/rfc822");  //set the email recipient
    emailIntent.putExtra(Intent.EXTRA_EMAIL, recipient);
    //let the user choose what email client to use
    startActivity(Intent.createChooser(emailIntent, "Send mail using...")); 

``}

This will work :)
This is what android documentation says about Intent.Extra_Email
-A string array of all "To" recipient email addresses.
So you should feed string properly You can read more over here
http://developer.android.com/guide/components/intents-common.html#Email y aquí http://developer.android.com/guide/topics/resources/string-resource.html Or use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

Respondido el 13 de enero de 16 a las 13:01

In Kotlin - Android

fun sendMail(
        activity: Activity,
        emailIds: Array<String>,
        subject: String,
        textMessage: String
    ) {


        val emailIntent = Intent(Intent.ACTION_SEND)
        emailIntent.type = "text/plain"
        emailIntent.putExtra(Intent.EXTRA_EMAIL, emailIds)
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject)
        emailIntent.putExtra(Intent.EXTRA_TEXT, textMessage)
        emailIntent.setType("message/rfc822")
        try {
            activity.startActivity(
                Intent.createChooser(
                    emailIntent,
                    "Send email using..."
                )
            )
        } catch (ex: ActivityNotFoundException) {
            Toast.makeText(
                activity,
                "No email clients installed.",
                Toast.LENGTH_SHORT
            ).show()
        }
    }

Also you can use [ val emailIntent = Intent(Intent.ACTION_SENDTO) ] to invoke direct email client

//argument of function
val subject = "subject of you email"
val eMailMessageTxt = "Add Message here"

val eMailId1 = "emailId1@gmail.com"
val eMailId2 = "emailId2@gmail.com"
val eMailIds: Array<String> = arrayOf(eMailId1,eMailId2)

//Calling function
sendMail(this, eMailIds, subject, eMailMessageTxt)

I hope this code snippet will help to kotlin developers.

respondido 29 nov., 19:06

private void callSendMeMail() {
    Intent Email = new Intent(Intent.ACTION_SEND);
    Email.setType("text/email");
    Email.putExtra(Intent.EXTRA_EMAIL, new String[] { "me@gmail.com" });
    Email.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
    startActivity(Intent.createChooser(Email, "Send mail to Developer:"));
}

Respondido 01 Oct 15, 12:10

It's saying no app can perform this action. - Abu Nayem

Un par de cosas:

1 - You need to set the action constant variable as ACTION_SENDTO.
Intent intentEmail = new Intent(Intent.ACTION_SENDTO);

2 - If you want it to be opened by only the mail then use the setData() method: intentEmail.setData(Uri.parse("mailto:")); Otherwise it will ask you to open it as text, image, audio file by other apps present on your device.

3 - You need to pass the email ID string as an array object and not just as a string. String is: "name@email.com". Array Object of the string is: new String[] {"email1", "email2", "more_email"}.

intentEmail.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@overflow.com", "abcd@stack.com"});

Respondido 01 Oct 18, 08:10

Esto es lo que me funciona:

val email = "recipient@email.com"
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:$email")
intent.putExtra(Intent.EXTRA_SUBJECT,"My Subject")
startActivity(intent)

Respondido el 08 de enero de 21 a las 12:01

Made me waste so much time! Thanks to the accepted answer! I'll add some Kotlin code with a couple of handy extension functions

fun Activity.hasEmailClient(): Boolean =
    emailIntent("someAddress", "someSubject", "someText")
        .resolveActivity(packageManager) != null

fun Activity.openEmailClient(address: String, subject: String, text: String) {
    startActivity(emailIntent(address, subject, text))
}

private fun emailIntent(address: String, subject: String, text: String): Intent =
    Intent(Intent.ACTION_SENDTO).apply {
        type = "text/plain"
        data = Uri.parse("mailto:")
        putExtra(Intent.EXTRA_EMAIL, arrayOf(address))
        putExtra(Intent.EXTRA_SUBJECT, subject)
        putExtra(Intent.EXTRA_TEXT, text)
    }

feel free to replace Activity with Fragment if it suits your needs. Example usage:

if (hasEmailClient()) {
    openEmailClient(
        "example@email.info",
        "this is the subject",
        "this is the text"
    )
}

Respondido el 08 de junio de 21 a las 18:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.