0

I am trying to view a local pdf in an external pdf viewer using this code:

Uri path = Uri.parse("android.resource://<package-name>/raw/Terms.pdf>");
    try
    {
     Intent intentUrl = new Intent(Intent.ACTION_VIEW);
     intentUrl.setDataAndType(path, "application/pdf");
     intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     getActivity().startActivity(intentUrl);
    }
    catch (ActivityNotFoundException e)
    {
     Toast.makeText(getActivity(), "No PDF Viewer Installed", Toast.LENGTH_LONG).show();
    }

Even though I have Adobe PDF installed, it throws an ActivityNotFoundExcecption.

Why is that?

deimos1988
  • 5,526
  • 7
  • 39
  • 56

1 Answers1

0

Few, if any, PDF viewing apps support the android:resource scheme. You need to provide your PDF file by some other means to PDF viewers, such as via FileProvider, so you can use a scheme (e.g., content) that is more likely to be supported.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367