通过电子邮件发送多个附件和预填邮件

时间:2016-06-26 19:54:59

标签: android email android-intent attachment

我做了以下事情:

Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { receiver });
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); // uris is a array list!

然后我尝试添加以下内容:

intent.putExtra(Intent.EXTRA_TEXT, "text");

这会添加一条日志行,抱怨该文本不是数组列表。虽然工作,但电子邮件没有正文

另外,我试过以下:

ArrayList<String> texts = new ArrayList();
for (int i = 0; i < uris.size(); i++)
    texts.add("Test");
intent.putParcelableArrayListExtra(Intent.EXTRA_TEXT, texts);

这会删除日志警告,但电子邮件仍然没有正文。

问题

如何将多个文件附加到邮件中并使用一些文本预填充正文?

2 个答案:

答案 0 :(得分:1)

  

如何将多个文件附加到邮件中并使用一些文本预填充正文?

一般来说,你没有。

引用the documentation for ACTION_SEND_MULTIPLE

  

get * ArrayListExtra可以 EXTRA_TEXT EXTRA_STREAM字段,包含要发送的数据

(强调补充)

您试图包含两者,这超出了Intent规范的范围。

用户可以从ACTION_SEND_MULTIPLE Intent中选择许多应用。这些应用对您的Intent的影响取决于这些应用的开发者。可能的候选人是:

  • 忽略EXTRA_TEXT,正如您所见
  • 忽略EXTRA_STREAM
  • 尊重两者
  • 严重崩溃

ACTION_SEND也是如此(您可以EXTRA_TEXTEXTRA_STREAM,而不是两者都有。“

答案 1 :(得分:1)

这是我的代码,我曾经将多个图片附加到电子邮件中。

$img_r = imagecreatefromjpeg('/home/user/site.com/wp-content/themes/my-theme/uploads/test.jpeg'); $new_canvas = imagecreatetruecolor(350, 350); imagecopyresampled($new_canvas, $img_r, 0, 0, 85, 13, 350, 350, 500, 500 ); imagejpeg($new_canvas, $src); imagedestroy($new_canvas);

这里我很难将2张图片编码为arraylist,我需要发送电子邮件意图选择器:

Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE); i.setType("image/png"); i.putExtra(Intent.EXTRA_SUBJECT, "EMAIL SUBJECT"); i.putExtra(Intent.EXTRA_TEXT, "Email Body content....");

现在将Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.slide_1); String path = MediaStore.Images.Media.insertImage(getContentResolver(), largeIcon, "title", null); Bitmap largeIcon1 = BitmapFactory.decodeResource(getResources(), R.drawable.slide_2); String path1 = MediaStore.Images.Media.insertImage(getContentResolver(), largeIcon1, "title", null); ArrayList<Uri> screenshotUri = new ArrayList<>(); screenshotUri.add(Uri.parse(path)); screenshotUri.add(Uri.parse(path1));添加到intent方法中。

ArrayList<Uri>

希望这会对你有帮助......

相关问题