Android通过Intent发送电子邮件含附件
File file =new File("/sdcard/android123.cwj"); //附件文件地址
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("subject", file.getName()); //
intent.putExtra("body", "android123 - email sender"); //正文
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); //添加附件,附件为file对象
if (file.getName().endsWith(".gz")) {
intent.setType("application/x-gzip"); //如果是gz使用gzip的mime
} else if (file.getName().endsWith(".txt")) {
intent.setType("text/plain"); //纯文本则用text/plain的mime
} else {
intent.setType("application/octet-stream"); //其他的均使用流当做二进制数据来发送
}
startActivity(intent); //调用系统的mail客户端进行发送
本文介绍如何在Android系统中使用Intent发送带有附件的电子邮件。仅需简单几行代码即可实现,支持多种文件类型。

283

被折叠的 条评论
为什么被折叠?



