通过使用以下代码,我尝试将多个文件附加到电子邮件,但在使用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"));
答案 0 :(得分:2)
试试这个,
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);
}
答案 1 :(得分:2)
尝试像这样的完整路径
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);