如何在Android系统中发送带附件的电子邮件呢? 其实通过Intent可以很方便的发送Email,只需要短短10行代码就可以处理,这里Android开发网就以在sdcard上的 android123.cwj文件为例,通过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客户端进行发送

更多相关文章

  1. Android之Adapter优化
  2. android JNI 使用 for mac
  3. PC 与 Android(安卓)的adb同步通信(一)
  4. 程序代码删除联系人的分组
  5. 百度地图 - Android所有Marker点显示在屏幕内
  6. Android(安卓)进阶——代码插桩必知必会之初识ASM7字节码操作库
  7. Android发送短信解决字数限制问题
  8. 好用的 Android(安卓)数据库 DBFlow
  9. RxJava(十)switchIfEmpty 操作符实现 Android(安卓)检查本地缓存逻

随机推荐

  1. Android_Layout_xml布局
  2. Android下2d物理引擎Box2d用法简单实例
  3. 为开发人员准备的 10 个 Android(安卓)教
  4. iOS url 编码 解码
  5. 蓝牙API
  6. Android(安卓)RxJava使用介绍(三) RxJava的
  7. android flash air 打包工具
  8. Android-基本控件(五大布局 Layout)
  9. 导入android工程没有R文件的解决办法
  10. android 事件分发机制(转载)