2012-02-01 11 views
75

Estoy tratando de usar un para enviar un correo electrónico desde mi aplicación, pero el campo Para del correo electrónico no se completará. Si agrego código para completar el asunto o el texto, funcionan bien. Solo el campo Para no se completará.Intent.EXTRA_EMAIL no rellena el campo Para

También he intentado cambiar el tipo a "text/plain" y "text/html" pero me sale el mismo problema. ¿Alguien puede ayudar, por favor?

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...")); } 

El cliente de correo electrónico que estoy tratando de utilizar Gmail es

Respuesta

186

creo que no está de paso recipient como array of string

así debería ser

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "[email protected]" }); 
+9

Android ... ¿por qué eres tan patético? –

+2

jajaja, me hiciste reir +1 Million @BugsHappen .. Razones: es una fuente abierta pero la documentación no es 100% satisfactoria, los fabricantes de dispositivos modifican según sus necesidades (la mayoría de los dispositivos son baratos e inútiles), los desarrolladores no leen "desarrollador" .android.com ". – MKJParekh

+4

También asegúrese de que * NO * está haciendo 'intent.putExtra (Intent.EXTRA_EMAIL, list.toArray())' ** NO FUNCIONARÁ, ya que list.toArray() produce Object [] y no String [] * * – kape123

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

Uso

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

``} 

Esto funcionará :)
Esto es lo que dice acerca de la documentación androide Intent.Extra_Email
-A matriz de cadenas de todos "a" Direcciones de correo electrónico del destinatario.
Por lo que debe alimentarse adecuadamente cadena Puede leer más aquí
http://developer.android.com/guide/components/intents-common.html#Email y aquí http://developer.android.com/guide/topics/resources/string-resource.html O utilizar la acción ACTION_SENDTO e incluir el "mailto:" esquema de datos. Por ejemplo:

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); 
} 
Cuestiones relacionadas