情况是这样的 - 我正在开发一个具有原生 Android 功能的 Unreal 插件。
对单个图像的 Intent 工作得很好,但现在,当我尝试使用 ACTION_SEND_MULTIPLE
添加多个图像附件时,它没有启动 Activity 。
没有错误,执行在 .startActivity()
上停止,使用 try-catch 包装不会返回任何异常,Unreal 传递图像数组没有任何问题。
我觉得它没有正确建立 Intent ,但经过 2 天的搜索和无数小时的尝试和错误,我觉得是时候放弃并在这里寻求建议了:)
这是我怀疑代码的 java 部分不起作用:
public static void sendEMail(Activity activity, String subject, String[] extraImagePaths,
String[] recipients, String[] cc, String[] bcc,
boolean withChooser, String chooserTitle) {
Intent intent = createEMailIntent(subject, recipients, cc, bcc);
ArrayList<Uri> paths = new ArrayList<Uri>();
if (extraImagePaths.length > 0) {
for (String extraImagePath : extraImagePaths) {
File fileIn = new File(extraImagePath);
Uri arrayPath = Uri.fromFile(fileIn);
paths.add(arrayPath);
}
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, paths);
try {
launchShareIntent(activity, withChooser, chooserTitle, intent);
} catch (Exception e) {
Log.d("AndroidLOG:", e.getMessage());
}
}
private static Intent createEMailIntent(String subject, String[] recipients, String[] cc, String[] bcc) {
return new Intent(Intent.ACTION_SEND_MULTIPLE)
.setData(Uri.parse("mailto:"))
.setType("image/*")
.putExtra(Intent.EXTRA_SUBJECT, subject)
.putExtra(Intent.EXTRA_EMAIL, recipients)
.putExtra(Intent.EXTRA_CC, cc)
.putExtra(Intent.EXTRA_BCC, bcc);
}
private static void launchShareIntent(Activity activity, boolean withChooser, String chooserTitle, Intent intent) {
if (withChooser) {
Intent chooserIntent = Intent.createChooser(intent, chooserTitle);
activity.startActivity(chooserIntent);
} else {
activity.startActivity(intent);
}
}
尝试删除除图像之外的所有额外内容,但这并没有解决问题。
非常感谢您的帮助!
最佳答案
经过更多挖掘后发现类似的帖子,将 .fromFile()
更改为 FileProvider
,它的工作就像一个魅力。
fragment :
for (String extraImagePath : extraImagePaths) {
Uri arrayPath = FileProvider.getUriForFile(activity, getAuthority(activity), new File(extraImagePath));
paths.add(arrayPath);
}
附注信用归CommonsWare !
关于java - 无法使用 Intent.ACTION_SEND_MULTIPLE 找到工作解决方案以将多个图像附加到电子邮件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59770815/