I use a ChooserIntent to add files to my Application.
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);
Normally, e.g. when choosing a file such as a picture from internal or external storage, this returns a content:// Uri in onActivityResult(). This also works fine with DropBox and most other storage mediums, but when using OneDrive, it returns a file:// Uri leading to a FileUriExposedException in Android SDK 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()
How can I either make OneDrive return files with a content:// Uri (preferably) or avoid the Exception from crashing my App?
So apparently Microsoft just wasn't aware of the problem and fixed it promptly after I sent a support ticket. Great support, but they should have fixed that problem with the launch of api 24.