无法从我的使用应用程序的意图附件发送电子邮件(Gmail中) [英] Unable to send email with attachments from my app using intents (Gmail)
问题描述
我试图发送包含在使用意图SD卡的文件夹文件(.log文件)。这是code:
I'm trying to send files (.log files) contained in a sdcard's folder using Intent. This is the code:
public void sendMail() {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"name.surname@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Log files");
intent.putExtra(Intent.EXTRA_TEXT, "body");
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
File root = Environment.getExternalStorageDirectory();
File logfolder = new File(root, "log");
for (String file : logfolder.list()){
Uri u = Uri.parse(file);
uris.add(u);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(Intent.createChooser(intent, new String("Send mail...")));
}
}
我从菜单中选择Gmail中。一旦Gmail的运行结束它显示与收件人,主题,正文邮件和附件正确的文件。该邮件sended,并没有错误,但我得到一个状态栏通知,上面写着无法显示附件!事实上收件人正确接收电子邮件,但它没有附件。
我无法弄清楚是什么问题。为什么附件不是sended?请帮助我!
I choose Gmail from menu. Once Gmail is opend it displays a mail with recipient, subject, text, and attachment files correctly. The mail is sended with no error but i get a status bar notification that says "couldn't show attachment"! In fact recipient receives email correctly but it has no attachment. I'm not able to figure out what is the problem. Why attachments are not sended? Please help me!!
推荐答案
确定。我找到解决方案。需要更换的:
Ok. i find the solution. Need to replace this:
for (String file : logfolder.list()){
Uri u = Uri.parse(file);
uris.add(u);
}
本:
for (File file : logfolder.listFiles()){
Uri u = Uri.fromFile(file);
uris.add(u);
}
这篇关于无法从我的使用应用程序的意图附件发送电子邮件(Gmail中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!