android 发送带附件的邮件
16lz
2021-01-23
// 附件文件地址
String fileName = items.get(arg2).get(NAME);
File file = new File(Environment.getExternalStorageDirectory(), fileName);
// 启动系统邮件
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("subject", file.getName());
// 正文
intent.putExtra("body", fileName);
// 添加附件,附件为file对象
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
// 如果是gz使用gzip的mime
if (file.getName().endsWith(".gz")) {
intent.setType("application/x-gzip");
}
// 纯文本则用text/plain的mime
else if (file.getName().endsWith(".txt")) {
intent.setType("text/plain");
}
// 其他的均使用流当做二进制数据来发送
else {
intent.setType("application/octet-stream");
}
// 调用系统的mail客户端进行发送。
startActivity(intent);
更多相关文章
- android 调用系统的图片选择
- ffmpeg3.3 编译 android 系统版本 32位 和64 位 动态库
- Android property系统分析
- Android判断网络是否可用,调用系统网络设置
- 非常不错的资金管理系统android版客户端源码
- PHP如何检测手机是什么系统?
- 调用android系统自带的功能