使用ChooserIntent从OneDrive下载文件时出现FileUriExposedException

时间:2017-06-27 10:53:05

标签: android android-intent uri android-intent-chooser

我使用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时,它会返回一个文件:// 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/myemail@email.com/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/myemail@email.com/5761/bewerbung.rtf exposed beyond app through Intent.getData()

如何使OneDrive返回带有内容的文件:// Uri(最好)或避免异常崩溃我的应用程序?

1 个答案:

答案 0 :(得分:0)

显然,微软在发送支持票后,并没有意识到这个问题并立即修复了。很大的支持,但他们应该通过api 24的发布来解决这个问题。