1

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

sanil
  • 482
  • 1
  • 7
  • 23
  • Well what is the problem? What is the question? Any errors? – blackapps Jan 17 '21 at 13:43
  • @blackapps pdf viewer not able to view the file which is saved at internal storage – sanil Jan 17 '21 at 13:52
  • You should better tell what happens and not happens. All steps please. We cannot see what happens on your phone . Tell it in your post. Dont use comments. – blackapps Jan 17 '21 at 13:55

0 Answers0