2017-02-27 194 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]"});