2012-10-30 81 views
1

我需要从我的Android应用程序发送电子邮件。因此,我向电子邮件客户端应用程序发送了2个参数(电子邮件和主题),但是当应用程序打开电子邮件客户端时,仅添加了主题参数,并且未设置电子邮件参数。在Android中发送电子邮件

我该如何解决这个问题?

String getMail = email.toString(); 
    Log.d("GET MAIL:",getMail); 
    String subject = "Subject"; 
    Intent emailIntent = new Intent(Intent.ACTION_SEND); 
    emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail); 
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 

// need this to prompts email client only             
emailIntent.setType("message/rfc822"); 
startActivity(Intent.createChooser(emailIntent,"Choose E-mail client:")); 

回答

2

变化emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);

到:

emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{getMail}); 
2

getMail应该是一个字符串数组...

3
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); 
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From App"); 

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));