0

I can get both Mail and Gmail to attach multiple csv files to an email.

When sent via Mail all the attachments are delivered.
When sent by Gmail none of the attachments are delivered.

I have read the documentation Send Binary Content. I have searched but only found a solution for Gmail that does not work with Mail. Mail seems happy with just about any approach. Gmail just doesn't want to play.

Has anyone found a solution for sending multiple attachments that works with both Mail and 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);

And the code used to create the file

 FileOutputStream fos = context.openFileOutput(path, Context.MODE_WORLD_READABLE);
 OutputStreamWriter writer = new OutputStreamWriter(fos);
 writer.append(builder.toString());
 writer.close();
 fos.close();
RobCroll
  • 2,571
  • 1
  • 26
  • 36

2 Answers2

0

The following code is a snippet from one of my apps. As far as I remember, it works with GMail and Mail (Can't verify it at the moment.). It looks basically like your solution, but with a few little differences. Maybe one of them is what you are looking for. :)

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);
forgemo
  • 4,634
  • 5
  • 22
  • 25
  • Thanks forgemo but no luck. I tried moving the setType method up and changing it to text/plain. Interested in how you are creating your files if indeed this code does work with Gmail – RobCroll Nov 07 '12 at 02:21
0

Here you can get detail information https://stackoverflow.com/a/18225100/942224

by using below code i am attaching image file in gmail or Mail.... hope it will help you

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);
Community
  • 1
  • 1
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • Thanks Sanket but I need to send multiple attachments, this solution only enables me to send a single attachment. The description explains this but I've improved the title so it's now clear. I need to send multiple documents. – RobCroll Nov 11 '12 at 22:53