0

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

当通过邮件发送时,所有附件都会被传递。
当通过 Gmail 发送时,不会传递任何附件。

我已阅读文档发送二进制内容。我已经搜索但只找到了一个不适用于 Mail 的 Gmail 解决方案。Mail 似乎对任何方法都很满意。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();
4

2 回答 2

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);
于 2012-11-06T23:05:16.593 回答
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);
于 2012-11-10T07:58:12.187 回答