2017-02-27 47 views
0

我得到没有错误,但邮件将不会显示!它保持为空发送邮件:Intent.EXTRA_EMAIL不起作用

public void Send_Mail(View view) { 
     String txt_context = "My comment about the App : \n The App is good but does not support v3"; 
     Intent intent = new Intent(Intent.ACTION_SEND); 
     intent.setData(Uri.parse("mailto:")); 
     intent.setType("message/rfc822"); // 
     intent.putExtra(Intent.EXTRA_EMAIL,"[email protected]"); // **this will not displayed** """ 
     intent.putExtra(Intent.EXTRA_SUBJECT,"Comment about the APP"); 
     intent.putExtra(Intent.EXTRA_TEXT,txt_context); 
     startActivity(intent); 

回答

0

这就是你如何通过意图正确发送电子邮件。如果不是,则需要URI参数才能让Gmail收到您的电子邮件。

Intent send = new Intent(Intent.ACTION_SENDTO); 
String uriText = "mailto:" + Uri.encode("[email protected]") + 
      "?subject=" + Uri.encode("the subject") + 
      "&body=" + Uri.encode("the body of the message"); 
Uri uri = Uri.parse(uriText); 

send.setData(uri); 
startActivity(Intent.createChooser(send, "Send mail...")); 
+0

你的代码的工作,但有我的代码不小的修改,这将没有大的变化的工作? – Testiest

0

我知道这个职位是旧的,但我遇到了同样的问题,我找到了解决办法(in the official documentation):

如前所述,Intent.EXTRA_EMAIL是:

一个String []持有电子邮件地址应该被传送到。

因此,要解决您的问题,而不是:

intent.putExtra(Intent.EXTRA_EMAIL,"[email protected]"); 

做:

intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});