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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 *