我已经生成了一个HTML代码(带有<html><body></body></html>
标记)作为字符串。现在我想把这段HTML代码作为HTML发送到邮件中。我的代码如下。
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"me@mydomain.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "I would like to buy the following");
intent.putExtra(Intent.EXTRA_TEXT, purchaseOrder());
startActivity(Intent.createChooser(intent, "sending mail"));
其中purchaseOrder()
是传递给我具有完整HTML代码的字符串的方法。但是,尽管GMail客户机在我的Nexus1上打开,但是它有一个包含所有HTML标记的字符串,而不是实际的HTML视图。我尝试了下面的方法,但是出错了。GMail崩溃了。
intent.putExtra(Intent.EXTRA_STREAM, purchaseOrder());
发布于 2010-12-09 10:22:59
这对我来说很有效:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
startActivity(Intent.createChooser(emailIntent, "Email:"));
但我注意到内联样式和图像标签被忽略了……
发布于 2012-06-24 05:37:46
如果我没记错的话,你要找的是
Html.fromHtml()
例如:
Html.fromHtml("<a href="www.google.com"> Google</a>");
这将使Google成为一个超链接
发布于 2015-02-05 15:54:45
这对我很有效,Intent.ACTION_SENDTO
,我的代码如下:
String mailId="yourmail@gmail.com";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto",mailId, null));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
// you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here");
// or get fancy with HTML like this
emailIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<a>http://www.google.com</a>")
.append("<small><p>More content</p></small>")
.toString())
);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
https://stackoverflow.com/questions/2544141
复制相似问题