Issue
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?
Solution
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[]{"[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
}
Answered By - PaulT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.