• Android 调用系统Email发送带多附件的邮件


    转自:http://www.open-open.com/lib/view/open1347005126912.html

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

      在Android中,调用Email有三种类型的Intent:

      Intent.ACTION_SENDTO  无附件的发送

      Intent.ACTION_SEND  带附件的发送

      Intent.ACTION_SEND_MULTIPLE  带有多附件的发送

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

      1.使用SENTTO发送

      

    1
    2
    3
    4
    5
    Intent data=new Intent(Intent.ACTION_SENDTO); 
    data.setData(Uri.parse("mailto:455245521@qq.com")); 
    data.putExtra(Intent.EXTRA_SUBJECT, "这是标题"); 
    data.putExtra(Intent.EXTRA_TEXT, "这是内容"); 
    startActivity(data);

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

      2.使用SEND发送

      

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Intent intent = new Intent(Intent.ACTION_SEND);
    String[] tos = { "fdafdafa@gmail.com" };
    String[] ccs = { "gegeff@gmail.com" };
    String[] bccs = {"fdafda@gmail.com"};
    intent.putExtra(Intent.EXTRA_EMAIL, tos);
    intent.putExtra(Intent.EXTRA_CC, ccs);
    intent.putExtra(Intent.EXTRA_BCC, bccs);
    intent.putExtra(Intent.EXTRA_TEXT, "body");
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
     
    intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Chrysanthemum.jpg"));
    intent.setType("image/*");
    intent.setType("message/rfc882");
    Intent.createChooser(intent, "Choose Email Client");
    startActivity(intent);

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

         Intent.EXTRA_EMAIL,

         Intent.EXTRA_CC,

         Intent.EXTRA_BCC

      来进行putExtra来设定的。

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

       3.使用SEND_MULTIPLE来进行多附件的发送

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    String[] tos = { "wingfourever@gmail.com" };
    String[] ccs = { "tongyue@gmail.com" };
    intent.putExtra(Intent.EXTRA_EMAIL, tos);
    intent.putExtra(Intent.EXTRA_CC, ccs);
    intent.putExtra(Intent.EXTRA_TEXT, "body");
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
     
    ArrayList<uri> imageUris = new ArrayList<uri>();
    imageUris.add(Uri.parse("file:///sdcard/Chrysanthemum.jpg"));
    imageUris.add(Uri.parse("file:///sdcard/Desert.jpg"));     
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
    intent.setType("image/*");
    intent.setType("message/rfc882");
    Intent.createChooser(intent, "Choose Email Client");
    startActivity(intent);</uri></uri>


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

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

      Android 调用系统Email发送带多附件的邮件

      

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

  • 相关阅读:
    执行序列oracle存储过程和序列化写的demo
    快捷键列表myeclipse 设置代码提示快捷键
    鼠标管理解决win8 插上usb/鼠标蓝屏或无效方法
    JQuery实现拼图数字游戏
    Django的admin定制
    Django报:AttributeError: tuple object has no attribute get
    Django的models方法返回值异常,待解决
    主页跳转子页面的时候,模板语句中的数据未返回到页面(子页面空白)
    Django报:builtin_function_or_method' object is not iterable
    Windows Azure SDK 1.5、Windows Azure Tools for Microsoft Visual Studio 2010和新的服务管理功能发布了
  • 原文地址:https://www.cnblogs.com/mochaMM/p/5168781.html
Copyright © 2020-2023  润新知