我的应用程式中有程式码,可让使用者传送电子邮件给开发人员。它应该预填充“收件人”字段,“主题”字段和“正文”字段。但是,当我运行时,它会填充到,但忽略其他主题,正文和选择器文本等其他文字。我在两种测试设备上看到了这种行为:一种正在运行Lollipop(Verizon三星Galaxy Note 4),另一种正在运行Jelly Bean 4.2.2(在CM10.1上为Samsung Fascinate),尽管我不知道这是否与问题有关。
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();
}
}
为什么在填充“收件人”电子邮件时会忽略“主题”和“正文”?
以下代码对我有用(尝试一下):
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句