0

I am new to android and trying to send the multiple files to gmail using the Intent. But its not sending the attached files. Please help me for this.

Below is the my code :

Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        targetedShare.setType("image/*"); // put here your mime type

        targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Amplimesh Photo");
        targetedShare.putExtra(Intent.EXTRA_TEXT,"Attached the Quote");

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

        //Fetching the Installed App and open the Gmail App.
        for(int index = 0; index < productList.size(); index++) {
            ByteArrayInputStream byteInputStream = new ByteArrayInputStream(productList.get(index).getOverlayBitmap());
            Bitmap overLayBitmap = BitmapFactory.decodeStream(byteInputStream);

            String fileName = SystemClock.currentThreadTimeMillis() + ".png";

            //Save the bitmap to cache.
            boolean isSaved = Helper.saveImageToExternalStorage(overLayBitmap, getApplicationContext(), fileName);
            if(isSaved)
                uris.add(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/amplimesh", fileName)));
        }
        targetedShare.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivityForResult(Intent.createChooser(targetedShare, "Sending multiple attachment"), 12345);
user2601652
  • 467
  • 2
  • 8
  • 26

3 Answers3

9

UPDATE

try with full path like this

uris.add(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg")));

use this

Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 

instead of

Intent share = new Intent(android.content.Intent.ACTION_SEND);

try this

 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);
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • 1
    I have updated the question with new code. But still its not working. When it open the Gmail app it show there attachment but its not sending attached files. – user2601652 Aug 14 '13 at 07:35
  • i dont know why we have to use image path like this.. but it was also works for me :) – Sanket Kachhela Aug 14 '13 at 07:51
0

Here is sample working code in our prj

ArrayList<Uri> imageUris = new ArrayList<Uri>();
imageUris.add(Uri.fromFile(new File("/mnt/sdcard/Medplann/IMG.jpg"))); // Add your image URIs here
imageUris.add(Uri.fromFile(new File("/mnt/sdcard/Medplann/Report.pdf")));

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
chaitanya
  • 1,726
  • 2
  • 17
  • 13
0

Try following code which i have used for Multiple attachment in one of my project.

public static void sendEmailWithMultipleAttachment(Context context,
        String caption, ArrayList<String> fileList) {
    Intent emailIntent = new Intent(
            android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("application/octet-stream");
    emailIntent.setType("message/rfc822"); // use from live device

    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, caption);

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

    for (String file : fileList) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    context.startActivity(Intent.createChooser(emailIntent,
            "Select email application."));
}

Here, ArrayList<String> fileList will be array of path of images or any file.

Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
  • I tried your code also. I have updated the question with new code. But still its not working. When it open the Gmail app it show there attachment but its not sending attached files. – user2601652 Aug 14 '13 at 07:40
  • @user2601652, hm... You are not passing full path in arraylist.. that is the problem my friend. Thats why I am thinking why my code is not running??? :) – Chintan Rathod Aug 14 '13 at 07:55