【发布时间】:2014-03-19 08:25:11
【问题描述】:
我想在 android 邮件中附加字符串作为 html 附件,我该如何实现。请帮助我使用 sn-p 来执行此操作。非常感谢。
【问题讨论】:
标签: android html string email-attachments
我想在 android 邮件中附加字符串作为 html 附件,我该如何实现。请帮助我使用 sn-p 来执行此操作。非常感谢。
【问题讨论】:
标签: android html string email-attachments
使用意图发送电子邮件,如下所示.. 如果您想添加一些字符串作为附件,您必须将该内容保存到带有 .html ext 的某个目录中,然后您可以将其作为附件添加到电子邮件意图中。 [此代码的想法可能需要根据您的应用要求进行少量修改..]
String emailText = "email message";
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demo@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hi");
emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
String attachContent = "<html> content </html>";
/* this method u have to write, to save the string into html file
into cache or any other dir */
saveFile(getCacheDir()+"/attach.html", attachContent );
File file = new File(root, getCacheWebDir()+"/attach.html");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
【讨论】: