【问题标题】:Android: ACTION_SEND_MULTIPLE with com.android.emailAndroid:带有 com.android.email 的 ACTION_SEND_MULTIPLE
【发布时间】:2011-07-27 20:49:32
【问题描述】:

我正在尝试将 Intent 中的多个附件发送到电子邮件应用程序(而不是 Gmail 应用程序)。我正在使用:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "sample@email.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"This is an email");
emailIntent.putExtra(Intent.EXTRA_TEXT, "This is the body");

File f1 = null;
File f2 = null;
try {
    f1 = new File("/sdcard/test");
    f2 = new File("/sdcard/test.1");
    FileWriter fw1 = new FileWriter(f1);
    FileWriter fw2 = new FileWriter(f2);
    fw1.write("this is some text");
    fw2.write("this is more text");
    fw1.close();
    fw2.close();
} catch (IOException e) {
    e.printStackTrace();
}

ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.fromFile(f1));
uris.add(Uri.fromFile(f2));
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);

startActivity(emailIntent);

当使用 Gmail 处理 Intent 时,它会显示两个附件,并且一切正常。当使用电子邮件应用程序时,不会添加任何附件。在 EXTRA_STREAM 中使用单个 Uri 时,单个附件有效,但使用 ArrayList 无效。我已经从这里提出的其他问题中拼凑出这段代码,但没有一个能解决这个问题。有人可以帮忙吗?

【问题讨论】:

    标签: android email android-intent


    【解决方案1】:

    我意识到这已经很晚了,但是您的意图类型是倒退的。应该是

    emailIntent.setType("text/plain");
    

    不是

    emailIntent.setType("plain/text");
    

    我很惊讶其他答案都没有指出这一点......

    【讨论】:

      【解决方案2】:

      使用

      emailIntent.setType(" */ * ");
      

      没有空格

      see hereACTION_SEND_MULTIPLE

      【讨论】:

        【解决方案3】:

        代替

        emailIntent.setType("plain/text");

        使用

        emailIntent.setType("application/octet-stream");

        我不知道为什么,但它对我有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-05-01
          • 1970-01-01
          • 2017-02-03
          • 2020-07-18
          • 2013-05-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多