众所周知,在Android中调用其他程序进行相关处理,几乎都是使用的Intent,所以,Email也不例外。

在Android中,调用Email有三种类型的Intent:
Intent.ACTION_SENDTO 无附件的发送
Intent.ACTION_SEND 带附件的发送
Intent.ACTION_SEND_MULTIPLE 带有多附件的发送



当然,所谓的调用Email,只是说Email可以接收Intent并做这些事情,可能也有其他的应用程序实现了相关功能,所以在执行的时候,会出现选择框进行选择。

1.使用SENTTO发送

[java] view plain copy
  1. Intentdata=newIntent(Intent.ACTION_SENDTO);
  2. data.setData(Uri.parse("mailto:way.ping.li@gmail.com"));
  3. data.putExtra(Intent.EXTRA_SUBJECT,"这是标题");
  4. data.putExtra(Intent.EXTRA_TEXT,"这是内容");
  5. startActivity(data);

通过向Intent中putExtra来设定邮件的相关参数。


2.使用SEND发送
[java] view plain copy
  1. Intentintent=newIntent(Intent.ACTION_SEND);
  2. String[]tos={"way.ping.li@gmail.com"};
  3. String[]ccs={"way.ping.li@gmail.com"};
  4. String[]bccs={"way.ping.li@gmail.com"};
  5. intent.putExtra(Intent.EXTRA_EMAIL,tos);
  6. intent.putExtra(Intent.EXTRA_CC,ccs);
  7. intent.putExtra(Intent.EXTRA_BCC,bccs);
  8. intent.putExtra(Intent.EXTRA_TEXT,"body");
  9. intent.putExtra(Intent.EXTRA_SUBJECT,"subject");
  10. intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///mnt/sdcard/a.jpg"));
  11. intent.setType("image/*");
  12. intent.setType("message/rfc882");
  13. Intent.createChooser(intent,"ChooseEmailClient");
  14. startActivity(intent);

很简单,发送邮件中,有收件者,抄送者,密送者。 也就是分别通过
Intent.EXTRA_EMAIL,
Intent.EXTRA_CC,
Intent.EXTRA_BCC

来进行putExtra来设定的,
而单个附件的发送,则使用Intent.EXTRA_STREAM来设置附件的地址Uri。


3.使用SEND_MULTIPLE来进行多附件的发送
[java] view plain copy
  1. Intentintent=newIntent(Intent.ACTION_SEND_MULTIPLE);
  2. String[]tos={"way.ping.li@gmail.com"};
  3. String[]ccs={"way.ping.li@gmail.com"};
  4. intent.putExtra(Intent.EXTRA_EMAIL,tos);
  5. intent.putExtra(Intent.EXTRA_CC,ccs);
  6. intent.putExtra(Intent.EXTRA_TEXT,"body");
  7. intent.putExtra(Intent.EXTRA_SUBJECT,"subject");
  8. ArrayList<uri>imageUris=newArrayList<uri>();
  9. imageUris.add(Uri.parse("file:///mnt/sdcard/a.jpg"));
  10. imageUris.add(Uri.parse("file:///mnt/sdcard/b.jpg"));
  11. intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,imageUris);
  12. intent.setType("image/*");
  13. intent.setType("message/rfc882");
  14. Intent.createChooser(intent,"ChooseEmailClient");
  15. startActivity(intent);

发送多个附件,最主要的时候,通过putParcelableArrayListExtra将多个附件的Uri地址List设置进去就OK了。其实还是很简单的。

更多相关文章

  1. android设备唯一码的获取,cpu号,mac地址
  2. Android AdbCommandRejectedException和cannot bind to套接字地
  3. Android开发包下载(包括开发所需所有安装包的下载方法与地址)
  4. Android 开发环境下载地址 -- 百度网盘 adt-bundle android-stud
  5. Android 网络编程 API笔记 - java.net 包 权限 地址 套接字 相关
  6. marsboard Android 4.4 添加开机自动设置静态IP地址

随机推荐

  1. android 丢包率的计算
  2. android ant
  3. 用Android(安卓)写休闲拼图游戏(一)
  4. Android(安卓)通过Intent 传递对象
  5. woyong
  6. android 自带的日期控件 DatePicker
  7. Android(安卓)ps 指令
  8. Android_播放器的进度条
  9. Cocos2d-x with Vungle Android(安卓)SDK
  10. instrumentation