用于发送带附件的电子邮件的 Android 意图 [英] Android Intent for sending email with attachment
本文介绍了用于发送带附件的电子邮件的 Android 意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
来自内部存储的电子邮件
收件人正在接收电子邮件,但没有附件.这是代码,有没有高手知道我哪里出错了?
The email is being received on by the recipient, but without the attachment. Here is the code, any expert knows where did I go wrong?
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
if (!file.exists() || !file.canRead()) {
Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
finish();
return;
}
Uri uri = Uri.parse("file://" + file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send email..."));
我没有收到任何吐司消息.谢谢.
I am not getting any toast message. Thanks.
推荐答案
该文件可能不是世界可读的.
The file is probably not world readable.
确实如此.尝试这样做:
indeed. Try doing this:
Uri uri = Uri.parse("file://" + file.getAbsolutePath());
这篇关于用于发送带附件的电子邮件的 Android 意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文