我生成了一个 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 View 。我尝试了以下但得到错误。 GMail 崩溃了。
intent.putExtra(Intent.EXTRA_STREAM, purchaseOrder());
最佳答案
这对我有用:
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:"));
但我注意到内联样式和图像标签被忽略了......
关于html - 使用 Android Intent 发送 HTML 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2544141/