FileUriExposedException同时下载从OneDrive文件与ChooserIntent

问题描述:

我用ChooserIntent将文件添加到我的应用程序。FileUriExposedException同时下载从OneDrive文件与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()。这也正常工作与Dropbox和大多数其他存储介质,但使用OneDrive时,它返回一个文件://乌里导致Android SDK中一个FileUriExposedException 24+。

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返回文件与内容:// URI(最好)或避免崩溃我的应用程序异常?

+0

你确定你使用的是最新OneDrive应用?他们本应该在〜9个月前解决这个问题,那就是Android 7.0的出货时间。您可以通过将'targetSdkVersion'设置为24以避免此问题,但这只是一个临时解决方案。 – CommonsWare

+0

是的,我是用从6月21日的最新版本,我想我会发送消息到Onedrive支持,看看他们有什么建议,或者如果他们可以改变任何事情。谢谢 :) –

因此很明显,微软只是没有意识到这个问题,并固定它及时我发了支持票之后。很大的支持,但他们应该有固定的问题,推出API的24