无法从内部存储或外部存储发送HTML文件作为邮件附件

时间:2012-12-17 23:34:14

标签: android email android-intent storage attachment

我一直在阅读,以至于(令人惊讶地)无法将文件作为邮件附件发送到内部存储器上(即使在MODE_WORLD_READABLE中)。

因此,我正在使用(脏)代码将文件复制到外部存储器,然后再发送邮件。

问题是,当我收到邮件时,附件不存在(虽然它在发送时显示为附件)!

然而,当我使用Root Explorer通过邮件手动发送文件时,一切都运行良好......

这是我的代码:

File sdDir = Environment.getExternalStorageDirectory();
File dir = getDir("MyApp", MODE_WORLD_READABLE);
copyFile(new File(dir.getAbsolutePath()+File.separator+Ref+"-"+Name+".html"), new File(sdDir+File.separator+Ref+"-"+Name+".html"));
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(sdDir+File.separator+ReservationReference+"-"+LastName+".html")); //"file://"+dir.getAbsolutePath()+File.separator+ReservationReference+"-"+LastName+".html"));
this.startActivity(Intent.createChooser(emailIntent, "Send by mail"));

提前谢谢你。

0 个答案:

没有答案