I'm trying to open a pdf after creating it via an intent. The file exists and is readable but save inside the apps directory.
Currently the file is saved in the following manner
//TODO: expose through a content provider
out = mContext.openFileOutput(outputFileName, Context.MODE_WORLD_READABLE);
final Intent viewIntent = new Intent();
E/PdfViewerActivity: fetchFile:file: java.io.FileNotFoundException: file does not exist
I found the answer starting with the Android 7 Behavior Changes documentation. Sharing files is no longer allowable when setting MODE_WORLD_READABLE even though the documentation doesn't mention any of this
I followed the documentation on sharing files to fix the issue but the sample code in the documentation was more complicated than what I needed. I still had to add the file provider to the AndroidManifest.xml as well as create the fileprovider.xml.
The resulting code is now
final Intent viewIntent = new Intent(); viewIntent.setAction(Intent.ACTION_VIEW); Uri fileUri = FileProvider.getUriForFile(mActivity, "my.authority.fileprovider", file); viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); viewIntent.setDataAndType(fileUri, "application/pdf");