Android的意图与附件发送电子邮件 [英] Android Intent for sending email with attachment

查看:135
本文介绍了Android的意图与附件发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  电子邮件从内部存储

该电子邮件被接收在由接收者,但没有附件。 这里是code,哪位高手知道在哪里我做错什么了?

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.

推荐答案

尝试:

Uri.fromFile(file);

来代替:

Uri.parse("file://" + file);

另外,尽量为text / xml 为您的MIME类型,假设这是一个XML文件作为变量名建议。

Also, try text/xml for your MIME type, assuming that this is an XML file as your variable name suggests.

这篇关于Android的意图与附件发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆