سؤال

By using following code, i am trying to attach multiple files to an E-Mail, but not getting attachments when using ArrayList.

public void sendImage() {
    // TODO Auto-generated method stub
    Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setType("message/rfc822");
    i.setClassName("com.google.android.gm",
            "com.google.android.gm.ComposeActivityGmail");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@domain.tld" });
    i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    i.putExtra(Intent.EXTRA_TEXT, "body of email");
    ArrayList<Uri> uris = new ArrayList<Uri>();
    String[] filePaths = new String[] {
            "file:///sdcard/Custom/CapturedVideo.mp4",
            "file:///sdcard/Custom/CapturedImage.jpg" };
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(i);
}

Note:- Earlier i was attaching single file to an EMail ! successfully !

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Custom/CapturedImage.jpg"));
هل كانت مفيدة؟

المحلول

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);

نصائح أخرى

Try with this one,

public void sendImage() {
    // TODO Auto-generated method stub
   Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("message/rfc822");
intent.setClassName("com.google.android.gm",
"com.google.android.gm.ComposeActivityGmail");
 intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@domain.tld" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intent.putExtra(Intent.EXTRA_TEXT, "body of email");
    ArrayList<String> fileList = new ArrayList<String>();
fileList.add(Environment.getExternalStorageDirectory()+"/Custom/CapturedVideo.mp4");
fileList.add(Environment.getExternalStorageDirectory()+"/Custom/CapturedImage.jpg");

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);
}

intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(intent);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top