Suhail Parvez Suhail Parvez - 1 year ago 101
Android Question

Open a Downloaded file (pdf) from the Downloads folder in the INTERNAL STORAGE

I have downloaded a file (133465.pdf) using the Download manager and now it is stored in the Downloads folder of the mobile phone (Internal storage).

How should i try and retrieve the downloaded pdf from the Downloads folder?

I am using the below code to try and retrieve the pdf from the downloads folder but i am getting an error on the Toast, saying "Cannot display PDF (133465.pdf cannot be opened)" .

String file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator + "133465.pdf";
Log.i("Fragmentadapter1", file);
File videoFile2Play = new File(file);
Intent i = new Intent();
i.setDataAndType(Uri.fromFile(videoFile2Play), "application/pdf");

I don't know if i am using the right file location to access the file.

Any help or suggestion will be appreciated.

Answer Source

If you are working for Lollopop and Below: You don't have to ask the user for permission on run-time. The manifest Permissions will do.

If you are working for Marshmellow and up: You have to ask the user for permission on run-time and act according to the users output.

Remember: You still have to give the Permissions on the Manifest too.

To Download a PDF on users Downloads folder :

DownloadManager downloadmanager;

    downloadmanager = (DownloadManager) getApplication().getSystemService(Context.DOWNLOAD_SERVICE);
    String url = hardcode + bb ;
    Uri uri = Uri.parse(url);
    DownloadManager.Request request = new DownloadManager.Request(uri)
            .setTitle(bb )
    Log.i("Download1", String.valueOf(request));


To View the Downloaded PDF from the Downloads folder of the Users device:

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + File.separator +
            "YOUR FILE NAME");
    Uri path = Uri.fromFile(file);
    Log.i("Fragment2", String.valueOf(path));
    Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW);
    pdfOpenintent.setDataAndType(path, "application/pdf");
    try {
    } catch (ActivityNotFoundException e) {


Note: Make sure u get the permission granted before downloading the Viewing the PDF file for Marshmellow and UP.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download