Android 调用系统Email --多附件

众所周知,在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:455245521@qq.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={"fdafdafa@gmail.com"};
  3. String[]ccs={"gegeff@gmail.com"};
  4. String[]bccs={"fdafda@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:///sdcard/Chrysanthemum.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={"wingfourever@gmail.com"};
  3. String[]ccs={"tongyue@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:///sdcard/Chrysanthemum.jpg"));
  10. imageUris.add(Uri.parse("file:///sdcard/Desert.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了。其实还是很简单的。


如下是在三星galaxy tab 2 10.1上面的运行效果:

对于使用邮件发送,在很多的Android应用中都会使用到,跟微博分享一样的常见。大家也只需要稍微了解下就可以了,毕竟还是很容易的。


转载请注明出处:http://blog.youkuaiyun.com/ml3947/


---------------------------------

最近公司平板上面的一个项目,要使用Email把日志导出的多页图片进行发送,也有其他的微博分享之类的功能。所以就稍微看了下调用Email发送多附件的,顺带着整理了下,写了这篇博客。


这周末本来打算和同事出去玩的,但貌似要下两天雨,如果真的是这样的话,我也会继续进行写JavaFX的相关博文。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值