Open PDF

How to open PDF in Android?

Open pdf

We have to put the ourexample.pdf in our divice, in this case in Android/data

File file =new File(Environment.getExternalStorageDirectory(),"Android/data/ExampleForm.pdf");

if (file.exists()) {
     Uri path = Uri.fromFile(file);
     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setDataAndType(path, "application/pdf");
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

     try {
        startActivity(intent);
     }
        catch (ActivityNotFoundException e) {
            Toast.makeText(MainActivity.this,
            "No Application Available to View PDF",
            Toast.LENGTH_SHORT).show();

        }
     }
}

Example in Github

Leave a Reply

Your email address will not be published. Required fields are marked *