Android ACTION_SEND 意图不填充主题或正文
Android ACTION_SEND intent not populating Subject or Body
我的应用程序中有代码可以让用户向开发人员发送电子邮件。它应该预填充收件人字段、主题字段和正文字段。但是,当我 运行 时,它填充到但忽略其他 EXTRA,如主题、正文和选择器文本。我在两台测试设备上看到了这种行为:一台 运行ning Lollipop (Verizon Samsung Galaxy Note 4) 和一台 运行ning 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();
}
}
为什么填充收件人电子邮件时主题和正文会被忽略?
试试这个对我有用的方法。
private void sendMail() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "xx@xx.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.mail_txt));
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
以下代码对我有用(刚试过):
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
}
确实遇到了这个问题,下面是我的解决方法:
检查电子邮件客户端(在我的特定情况下是 Gmail)是否只是重新使用未发送的原始邮件而不是撰写新电子邮件,因为这样做时客户端似乎忽略了 Intent.EXTRA_SUBJECT
和Intent.EXTRA_TEXT
.
Intent intent = new Intent(INTENT.ACTION_SENDTO);
仅调出电子邮件客户端,但出于某种原因不会填充某些设备中的 SUBJECT
和 BODY
字段。 (我认为这些是边缘情况)。
Intent intent = new Intent(INTENT.ACTION_SEND);
调出所有可以发送多部分消息的应用程序,例如:WhatsApp、Telegram、Gmail 等,但始终填充所有设备中的 SUBJECT
和 BODY
字段。
我的应用程序中有代码可以让用户向开发人员发送电子邮件。它应该预填充收件人字段、主题字段和正文字段。但是,当我 运行 时,它填充到但忽略其他 EXTRA,如主题、正文和选择器文本。我在两台测试设备上看到了这种行为:一台 运行ning Lollipop (Verizon Samsung Galaxy Note 4) 和一台 运行ning 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();
}
}
为什么填充收件人电子邮件时主题和正文会被忽略?
试试这个对我有用的方法。
private void sendMail() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "xx@xx.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.mail_txt));
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
以下代码对我有用(刚试过):
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
}
确实遇到了这个问题,下面是我的解决方法:
检查电子邮件客户端(在我的特定情况下是 Gmail)是否只是重新使用未发送的原始邮件而不是撰写新电子邮件,因为这样做时客户端似乎忽略了 Intent.EXTRA_SUBJECT
和Intent.EXTRA_TEXT
.
Intent intent = new Intent(INTENT.ACTION_SENDTO);
仅调出电子邮件客户端,但出于某种原因不会填充某些设备中的 SUBJECT
和 BODY
字段。 (我认为这些是边缘情况)。
Intent intent = new Intent(INTENT.ACTION_SEND);
调出所有可以发送多部分消息的应用程序,例如:WhatsApp、Telegram、Gmail 等,但始终填充所有设备中的 SUBJECT
和 BODY
字段。