3

I know I can use the following code to invoke default email client of Android to send email.
In plain text supported email client I need to use "\n" to make a newline, but in html supported email client I need to use "<br/>" to make a newline.
How can know what kind of email client supported? Thanks!

Intent emailIntent=new Intent(Intent.ACTION_SEND);         

String subject = "Your sms sent by email";
String body = "aa"+"<br/>"+"bb";

String[] extra = new String[]{"aa@gmail.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, extra);

emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.setType("message/rfc822");

startActivity(emailIntent);

1 Answers1

1

You have EXTRA_TEXT and EXTRA_HTML_TEXT.

Populate both of them, first with plain text, second with text formatted in html.

If users client supports html it will display html version if not it will display not formatted.

EXTRA_TEXT is required by standards and You always have to provide it, html version is optional.

For lower APIs there is ShareCompat.IntentBuilder in support library.

Edit:

I did a little test and it looks like EXTRA_HTML_TEXT is completely ignored.

This answer explains how to send html emails. In case if users client doesn't support HTML he will get exactly same message stripped out off all html tags.

Community
  • 1
  • 1
Gustek
  • 3,680
  • 2
  • 22
  • 36
  • Thanks! but EXTRA_HTML_TEXT require API minSdkVersion 16, now my app is only 8 –  May 29 '13 at 08:25
  • see updated. If needed I may provide sample code, but I think it shouldn't give any troubles how to use it. – Gustek May 29 '13 at 08:35
  • updated, but it looks like You won't have to make lots of changes. – Gustek May 29 '13 at 10:08