要发送多个附件,我使用以下代码创建邮件意图:
private Intent buildIntent(FotoBatch fotos) {
Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
email.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{MAIL_RECIPIENT});
...
// Attachments
ArrayList<Uri> uris = new ArrayList<>();
for (Foto foto : fotos.getFotos()) {
uris.add(foto.getUri());
}
email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
return email;
}
有多个附件时,会出现以下错误消息
使用GMail:
2018-10-16 12:07:19.703 4456-4456/? E/Gmail: Gmail:Error adding attachment
exk: SecurityException when openFileDescriptor.
at exl.a(SourceFile:8)
...
使用K9 Mail:
Caused by: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{a320841 7869:com.fsck.k9/u0a195} (pid=7869, uid=10195) that is not exported from UID 10196
at android.os.Parcel.readException(Parcel.java:1943)
清单包含提供者条目
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.timeshuttle.lagerapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
file_paths.xml的内容:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="my_images" path="Android/data/com.timeshuttle.lagerapp/files/Pictures" />
</paths>
内容提供商配置中缺少什么?
在Android 8.0设备上测试了Android API级别27。
如果附件列表仅包含一项,则没有错误。邮件应用程序将打开并正确显示附件(图像)。