我使用 ChooserIntent 将文件添加到我的应用程序。
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setType("*/*");
Intent chooserIntent = Intent.createChooser(intent,"Choose file to import";
startActivityForResult(chooserIntent, FILE_REQUEST_CODE);
通常,例如,当从内部或外部存储中选择诸如图片之类的文件时,这会在 onActivityResult() 中返回 content:// Uri。这也适用于 DropBox 和大多数其他存储介质,但在使用 OneDrive 时,它返回一个 file:// Uri,导致 Android SDK 24+ 中的 FileUriExposedException。
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=42, result=-1, data=Intent
{ act=android.intent.action.GET_CONTENT dat=file:///data/user/0/com.microsoft.skydrive/no_backup/stream_cache/[email protected]/5761/bewerbung.rtf typ=text/rtf flg=0x1000003 cmp=com.microsoft.skydrive/.intent.getcontent.ReceiveGetContentActivity }}
to activity {com.android.documentsui/com.android.documentsui.picker.PickActivity}:
android.os.FileUriExposedException: file:///data/user/0/com.microsoft.skydrive/no_backup/stream_cache/[email protected]/5761/bewerbung.rtf exposed beyond app through Intent.getData()
我怎样才能让 OneDrive 返回带有 content:// Uri 的文件(最好)或避免异常崩溃我的应用程序?
很明显,微软只是没有意识到这个问题,并在我发送了支持票后立即修复了它。很好的支持,但他们应该在 api 24 的发布中解决了这个问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句