Android使用系统内置邮件发送邮件

来源:互联网 发布:web文件服务器软件 编辑:程序博客网 时间:2024/04/27 14:16
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客户端进行发送
 

 

原创粉丝点击