I'm trying to send an e-mail containing HTML, but the HTML shows up literally. How can I send an HTML link? 开发者_Python百科Here's my current code:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"[EMAIL PROTECTED]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"<html><body>Example</body></html>");
context.startActivity(Intent.createChooser(emailIntent, "Send
mail..."));
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<a href=\"" + link_val + "\">" + text_value+ "</a>"));
There seems to be bugs in both gmail and email apps on Android. The email app cannot send links correctly if you put it into html, gmail sends the link okay. Gmail doesn't display the email with the links though, and the email app does display them correctly so they are clickable. At least it is the case if you are using custom uri's.
API 16++ has android.content.Intent.EXTRA_HTML_TEXT
You can use the android.support.v4.content.IntentCompat.EXTRA_HTML_TEXT
on APIs before 16. You should add this as an extra to the intent you normally use.
Also when specifying HTML text you need to add regular alternative text as well
So your code would look like
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"[EMAIL PROTECTED]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject");
emailIntent.putExtra(android.support.v4.content.IntentCompat.EXTRA_HTML_TEXT,
"<html><body>Example</body></html>");
context.startActivity(Intent.createChooser(emailIntent, "Send
mail..."));
精彩评论