通过使用以下代码,我试图将多个文件附加到电子邮件中,但使用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[] { "[email protected]" });
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"));
最佳答案
试试这样的完整路径
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);
关于android - 将多个文件附加到SD卡的电子邮件中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21627125/