我一直在使用我使用的 Android 程序来发送带有附件(文本/纯文本)的电子邮件Intent
但是Intent.ACTION_SEND
,Intent.putParcelableArrayListExtra(android.content.Intent.EXTRA_STREAM, uri)
当我尝试通过多次调用将多个文件附加到同一封邮件时Intent.putExtra(android.content.Intent.EXTRA_STREAM, uri)
,它无法正常工作。电子邮件中未显示任何附件。在此先感谢
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
System.out.println(emailText+emailTo);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailText);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailTo});
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
try
{
for (String file : filePaths)
{
File fileIn = new File(context.getFilesDir(),file);
System.out.println(fileIn+"yes");
Uri u = Uri.fromFile(fileIn);
uris.add(u);
System.out.println(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uris);
context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}