Android ACTION_SEND 意图不填充主题或正文

Sco*_*ott 3 android android-intent

我的应用程序中有代码,可让用户向开发人员发送电子邮件。它应该预填充 To 字段、Subject 字段和 body 字段。但是,当我运行时,它会填充 To 但忽略其他 EXTRA,如主题、正文和选择器文本。我在两台测试设备上看到了这种行为:一台运行 Lollipop(Verizon Samsung Galaxy Note 4)和一台运行 Jelly Bean 4.2.2(Samsung Fascinate on CM10.1,虽然我不知道这是否与问题有关.

private void sendHelpEmail() {
    Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
    // prompts email clients only
    email.setType("message/rfc822");

    email.putExtra(Intent.EXTRA_EMAIL, new String[] {getString(R.string.about_email)});
    email.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.login_help_subject));
    email.putExtra(Intent.EXTRA_TEXT, getString(R.string.login_help_body, classButton.text(), Txt_Student.getText().toString()));

    try {
        // the user can choose the email client
        startActivity(Intent.createChooser(email, getString(R.string.login_help_chooser)));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(mThis, R.string.login_help_error, Toast.LENGTH_LONG).show();
        }
}
Run Code Online (Sandbox Code Playgroud)

为什么在填充收件人电子邮件时主题和正文会被忽略?

Pau*_*ulT 6

以下代码适用于我(刚刚尝试过):

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"foo@bar.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
  startActivity(Intent.createChooser(i, "Choose email...");
} catch (android.content.ActivityNotFoundException ex) {
    // handle edge case where no email client is installed
}
Run Code Online (Sandbox Code Playgroud)