通过意图发送电子邮件

时间:2012-12-20 01:19:29

标签: android android-intent

我目前正在开发一个Android项目,我正在添加一个首选项,以便能够向我发送电子邮件。我使用ACTION_SENDTO意图发送电子邮件,但它回来后说No apps can perform this action

以下是我正在使用的代码

Intent intent = new Intent(Intent.ACTION_SENDTO);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_EMAIL, "someone@example.com");
                intent.putExtra(Intent.EXTRA_SUBJECT, "Check out this android app");
                intent.putExtra(Intent.EXTRA_TEXT, "Check out this new app in the Google Play Store. Its from Boardies IT Solutions and is called Boardies Password Manager. You can find it at https://play.google.com/store/apps/details?id=com.BoardiesITSolutions.PasswordManager");
                startActivity(Intent.createChooser(intent, "Send Email"));

感谢您提供的任何帮助

2 个答案:

答案 0 :(得分:1)

您需要添加以下内容

  

intent.setData(Uri.parse(“mailto:”+“email@bla.com”)); //离开   空白,如果不是特异性

答案 1 :(得分:0)

我认为您应该将Intent.ACTION_SENDTO替换为Intent.ACTION_SEND
希望这对你有用。

这段代码怎么样:

final Intent emailLauncher = new Intent(Intent.ACTION_SEND);
emailLauncher.setType("message/rfc822");
emailLauncher.putExtra(Intent.EXTRA_EMAIL, "username@domain.com");
emailLauncher.putExtra(Intent.EXTRA_SUBJECT, "check this subject line");
emailLauncher.putExtra(Intent.EXTRA_TEXT, "hey check this message body!");
try{
       startActivity(emailLauncher);
}catch(ActivityNotFoundException e){

}
相关问题