0

I am trying to display multiple pdf files in ViewPager using web view.

I am able to fetch the path of pdf files in onActivityResult. But path is showing

/content:/com.android.providers.downloads.documents/document/8828

. web view is not loading . I tried by hardcoding value Here is my code :

    val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("application/pdf");
    intent.action = Intent.ACTION_GET_CONTENT
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true)
    startActivityForResult(intent, PDF_EXPLORER_REQUEST_CODE)

and in onActivityResult

val mImageUri = data.data.path   
webview.loadUrl(mImageUri.toString())

I tries by getting actual path of pdf in phone webview.loadUrl(/storage/emulated/0/Download/dummy.pdf)

if I hardcode some url like htts://www.goole.com webview is loading. But not loading my local pdfs.

how to do this?

James Z
  • 12,209
  • 10
  • 24
  • 44
Kishor
  • 376
  • 4
  • 14
  • Possible duplicate of [How to get the Full file path from URI](https://stackoverflow.com/questions/13209494/how-to-get-the-full-file-path-from-uri) – Vihaari Varma Jul 17 '18 at 12:25
  • Refer to https://stackoverflow.com/questions/13209494/how-to-get-the-full-file-path-from-uri Load the path instead. – Vihaari Varma Jul 17 '18 at 12:27
  • A webview cannot display a pdf file to begin with. Like notepad on windows either ;-). – greenapps Jul 17 '18 at 14:43

1 Answers1

0

Webview cant load local(sdcard) pdf file, If you want to load sdcard pdf file you can use third party lib for it

https://github.com/barteksc/AndroidPdfViewer

or

You can use this method if you want

https://stackoverflow.com/a/43087727/4951663

Mohit Suthar
  • 8,725
  • 10
  • 37
  • 67