使用Android在Mail和Gmail中获取多个电子邮件附件

时间:2012-10-31 06:47:40

标签: android

我可以同时使用Mail和Gmail将多个csv文件附加到电子邮件中。

通过邮件全部发送时,附件将被发送 如果通过Gmail发送,则会传递附件。

我已阅读文档Send Binary Content。我搜索过但只找到了一个与Mail不兼容的Gmail解决方案。邮件似乎对任何方法都很满意。 Gmail根本不想玩。

是否有人找到了发送多个适用于Mail和Gmail的附件的解决方案?

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
String subject = context.getString(R.string.export_data_email_header);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.setType("text/csv");

ArrayList<Uri> uris = new ArrayList<Uri>();
if (diariesSelected) uris.add(Uri.fromFile(context.getFileStreamPath("diaries.csv")));
...
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

context.startActivity(emailIntent);

用于创建文件的代码

 FileOutputStream fos = context.openFileOutput(path, Context.MODE_WORLD_READABLE);
 OutputStreamWriter writer = new OutputStreamWriter(fos);
 writer.append(builder.toString());
 writer.close();
 fos.close();

2 个答案:

答案 0 :(得分:0)

以下代码是我的某个应用的代码段。据我所知,它适用于GMail和Mail(目前无法验证它。)。它看起来基本上像你的解决方案,但有一点点差异。也许其中一个就是你要找的东西。 :)

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "address@mail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "The subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "The actual message");

ArrayList<Uri> attachmentUris = new ArrayList<Uri>();

for (File attachment : attachments) {
    attachmentUris.add(Uri.fromFile(attachment));
}

emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUris);

startActivity(emailIntent);

答案 1 :(得分:0)

您可以在此处获取详细信息https://stackoverflow.com/a/18225100/942224

通过使用下面的代码我在gmail或Mail中附加图像文件....希望它能帮到你

Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ei.setType("plain/text");
        ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
        ei.putExtra(Intent.EXTRA_SUBJECT, "That one works");

        ArrayList<String> fileList = new ArrayList<String>();
        fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg");
        fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/certificate.jpg");
        fileList.add(Environment.getExternalStorageDirectory()+"/foldername/Aa.pdf");

        ArrayList<Uri> uris = new ArrayList<Uri>();
        //convert from paths to Android friendly Parcelable Uri's

        for (int i=0;i<fileList.size();i++)
        {
            File fileIn = new File(fileList.get(i));
            Uri u = Uri.fromFile(fileIn);
            uris.add(u);
        }

        ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivityForResult(Intent.createChooser(ei, "Sending multiple attachment"), 12345);