我正在尝试将文本文件附加到电子邮件中,我收到一个奇怪的错误,希望有人可以帮助我。当用户从选择器中选择gmail应用程序时,它工作正常,但如果他们选择内置邮件应用程序,他们会看到一个“无法附加文件”的Toast。
代码如下所示:
public static void sendMail(Context context, String emailBody, String emailSubject, String emailAddress, String attachmentFilename){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { emailAddress});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
if(attachmentFilename != null) {
//Add the attachment by specifying a reference to our custom ContentProvider and the specific file of interest
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + Settings.VYPR_LOG_PROVIDER_AUTHORITY + "/" + attachmentFilename));
}
context.startActivity(emailIntent);
}
任何人都对这里可能发生的事情有任何想法?我在这里看到的大部分内容都与SD卡上的附件有关。我实际上自己并没有写这个代码,但似乎这不是问题,因为如果用户选择gmail应用程序而不是内置的应用程序, 工作。
提前致谢!
答案 0 :(得分:1)
很久以前我遇到过同样的问题。必须强制使用Gmail应用程序发送附件。我无法弄清楚为什么内置的电子邮件应用程序无效。
如果您尝试接收特定电子邮件地址的附件,您还可以考虑部署Web服务来上传附件。
希望它有所帮助。