0

I am trying to display a PDF file from a URL but I am not able to open it with my function below. It returns me "The document path is not valid" error.

private void DownloadPdf(String strURL) {
        try {
            String extStorageDirectory = Environment
                    .getExternalStorageDirectory().toString();
            File folder = new File(extStorageDirectory, "pdf");
            folder.mkdir();
            File file = new File(folder, "test123.pdf");
            try {
                file.createNewFile();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            Downloader.DownloadFile(strURL, file);
            OpenPdf();
        } catch (Exception e) {
            // e.printStackTrace();
        }
    } catch (Exception ex) {

    }
}

private void OpenPdf() {
    File file = new File(Environment.getExternalStorageDirectory()
            + "/pdf/Read.pdf");
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(file);
    intent.setDataAndType(uri, "application/pdf");
    startActivity(intent);
}
birdcage
  • 2,638
  • 4
  • 35
  • 58

0 Answers0