簡體   English   中英

將多個文件附加到SD卡的電子郵件中

[英]Attach multiple files to EMail from SD Card

通過使用以下代碼,我試圖將多個文件附加到電子郵件 ,但在使用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);
}

注意:-之前我將單個文件附加到電子郵件中 成功!

i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Custom/CapturedImage.jpg"));

試試這個

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

嘗試這樣的完整路徑

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

用這個

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

代替

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

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM