2012-10-30 122 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..."));