0

I have kept a pdf file 'test.pdf' in side a folder called 'DocFile' and put that file inside asses folder for android.

Now when I tried to show that pdf on webview, it was not showing anything (nothing but a blank webview).

app/assets/android/DocFile/test.pdf

On controller

myWebView.url = '/DocFile/test.pdf';

But the same code works for IOS. Please suggest.

Raju Mahato
  • 129
  • 2
  • 14

1 Answers1

1

webview will not show your pdf. same problem i have face long back just use below code

File file = new File("/sdcard/sample.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(
                                        sample.this,
                                        "No Application Available to View PDF",
                                        Toast.LENGTH_SHORT).show();
                            }
user3563954
  • 37
  • 1
  • 13
  • I'm using this code but getting error on 'path' in intent.setDataAndType(path, "application/pdf"); please tell me what i can add in variable path – Ashutosh Salodkar Jun 06 '15 at 04:56