I am trying to open a pdf file which is stored on a internal storage but not able to view it. Below is my code snippet to save file on internal storage.
try (FileOutputStream fos = openFileOutput("demo.pdf", Context.MODE_PRIVATE)) {
fos.write(inputStream.read(buffer));
}
Code to open pdf file:
File file = new File(getFilesDir(), "demo.pdf");
Uri fileUri= FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".opener.provider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(photoURI, "application/pdf");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
opener_path.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="." />
<cache-path name="cache" path="." />
<external-files-path name="external-files" path="." />
<external-cache-path name="external-cache" path="." />
<external-path name="external" path="." />
</paths>
In AndroidManifest.Xml
<provider
android:authorities="${applicationId}.opener.provider"
android:exported="false"
android:grantUriPermissions="true"
android:name="com.demo.fileopener2.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/opener_paths" />
</provider>
Any help will be appreciated. Thank you