Android - 打开电子邮件应用程序?

ary*_*axt 40 email android android-intent android-activity

我想在我的Android应用程序上打开电子邮件应用程序:以下代码崩溃我做错了什么?请提供代码

Intent i = new Intent (Intent.ACTION_SEND,Uri.fromParts("mailto", "testemail@gmail.com", null));
this.startActivity(i);
Run Code Online (Sandbox Code Playgroud)

eLo*_*ato 93

/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text");

/* Send it off to the Activity-Chooser */
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Run Code Online (Sandbox Code Playgroud)

试试这个,它更清楚一点.尽管如此,只有在真实手机中使用该应用程序时,电子邮件的意图才有效,因此如果您使用的是模拟器,请在真实手机上试用.

  • 使用`emailIntent.setType("message/rfc822");`如果你想对它正确的话 (3认同)
  • 对我来说,只能使用"Intent.ACTION_SENDTO"动作. (2认同)
  • 添加这些以确保选择器仅显示电子邮件应用程序:`Intent i = new Intent(Intent.ACTION_SENDTO); i.setType("message/rfc822");` `i.setData(Uri.parse("mailto:"));` (2认同)

til*_*lak 7

尝试这个 :

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.parse("mailto:"
            + "xyz@abc.com"
            + "?subject=" + "Feedback" + "&body=" + "");
    intent.setData(data);
    startActivity(intent);
Run Code Online (Sandbox Code Playgroud)