Send Email Intent

前端 未结 30 3280
忘掉有多难
忘掉有多难 2020-11-22 07:27
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(\"text/html\");
intent.putExtra(Intent.EXTRA_EMAIL, \"emailaddress@emailaddress.com\");
intent.putExtr         


        
30条回答
  •  清酒与你
    2020-11-22 07:50

    If you want to target Gmail then you could do the following. Note that the intent is "ACTION_SENDTO" and not "ACTION_SEND" and the extra intent fields are not necessary for Gmail.

    String uriText =
        "mailto:youremail@gmail.com" + 
        "?subject=" + Uri.encode("your subject line here") + 
        "&body=" + Uri.encode("message body here");
    
    Uri uri = Uri.parse(uriText);
    
    Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
    sendIntent.setData(uri);
    if (sendIntent.resolveActivity(getPackageManager()) != null) {
       startActivity(Intent.createChooser(sendIntent, "Send message")); 
    }
    

提交回复
热议问题