zoukankan      html  css  js  c++  java
  • Android通过Intent发送电子邮件含附件

    如何在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客户端进行发送

  • 相关阅读:
    #树#遍历#N叉树的前序遍历
    #树#递归#最大二叉树II
    #树#递归#二叉树的镜像
    #树#递归#最大二叉树
    #树#二叉搜索树的最近公共祖先
    #树#二叉树的直径
    #树#N叉树的后序遍历
    #树#判断平衡二叉树
    webpack+react+nodejs+express前端开发环境搭建
    sublime 玩转react+es6
  • 原文地址:https://www.cnblogs.com/tt_mc/p/1800812.html
Copyright © 2011-2022 走看看