Android ACTION_SEND意图未填充主题或正文 [英] Android ACTION_SEND intent not populating Subject or Body

查看:110
本文介绍了Android ACTION_SEND意图未填充主题或正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中包含代码,该代码使用户可以向开发人员发送电子邮件.它应该预先填充收件人"字段,主题"字段和正文"字段.但是,当我运行时,它会填充到,但忽略其他主题,正文和选择器文本之类的EXTRA.我在两种测试设备上看到了这种行为:一种正在运行Lollipop(Verizon三星Galaxy Note 4),另一种正在运行Jelly Bean 4.2.2(在CM10.1上为Samsung Fascinate),尽管我不知道这是否与问题有关

I have code in my app which lets the user send an email to the developer. It is supposed to prepopulate the To field, the Subject field, and the body field. HOwever, when I run, it populates To but ignores the other EXTRAs like Subject, Body, and Chooser text. I'm seeing this behavior on two test devices: one running Lollipop (Verizon Samsung Galaxy Note 4) and one running Jelly Bean 4.2.2 (Samsung Fascinate on CM10.1, although I don't know if this has bearing on the issue.

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();
        }
}

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

Why would Subject and Body get ignored when the To email is populated?

推荐答案

以下代码对我有用(刚刚尝试过):

The following code works for me (just tried it):

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
}

这篇关于Android ACTION_SEND意图未填充主题或正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆