【发布时间】:2018-10-26 11:20:25
【问题描述】:
我正在尝试分享一张照片,我成功创建了一个 Intent:
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
_currentImagePosition = _viewPager.getCurrentItem();
Uri uri = Uri.fromFile((new File(_imageUrls.get(_currentImagePosition))));
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;
}
我单击“共享”图标,然后出现共享选项列表 - 没关系。 例如,只要我单击 Whatsapp 图标,我就会得到异常:
2018-10-26 13:57:39.497 21256-21256/com.eibimalul.smartgallery E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.eibimalul.smartgallery, PID: 21256
android.os.FileUriExposedException: file:///storage/0000-0000/DCIM/Camera/20181013_103421.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:944)
我做错了什么?
已编辑: 这与其他链接建议的问题不同,也不需要相同的解决方案(请参阅我接受的答案)。 是的,这是同样的例外,但是在链接中,他无法读取文件,我读取文件和创建 Intent 没有问题,当我实际单击要共享的应用程序的图标时,崩溃发生在我身上文件。
如果有人得到我的方案并寻找解决方案,我不确定他会在链接中找到那个简单甚至有用的方案 - 我没有.. :)
【问题讨论】:
标签: android android-intent share