title: How to open local pdf file in WebView Android Studio
body: <p>I am aware that this question has been asked many times, but I still cannot get it to work. I have a pdf in the raw folder and I am trying to open it in a webview using "<a href="https://drive.google.com/viewerng/viewer?embedded=true&amp;url=" rel="nofollow noreferrer">https://drive.google.com/viewerng/viewer?embedded=true&amp;url=</a>" to open it in the webview. </p>
  
  <p>I think my problem is I can't get the correct path for the pdf file. I've tried it three different ways, and either the webview says I get an error (the url doesn't exist), or it "opens" the pdf, but the webview displays this text in the middle, "No preview available".</p>
  
  <p>These are the three ways I've tried to get the path of the file.</p>
  
  <ol>
  <li>"android.resource://com.an.example/raw/filename"</li>
  <li>"android.resource://" + getPackageName() + "/" + R.raw.filename;</li>
  <li>Environment.getExternalStorageDirectory() + "/filename.pdf"</li>
  </ol>
  
  <p>For methods 1 and 3 I have tried "filename" and "filename.pdf"</p>
  
  <p>None of these are allowing the pdf to load in the webview. Below is the code I use to load the pdf. (Note: this method does work if I use a web url and not a local file)</p>
  
  <pre><code>    webview = (WebView) findViewById(R.id.webView);
      webview.getSettings().setJavaScriptEnabled(true);
  
      webview.getSettings().setBuiltInZoomControls(true);
  
      String pdf = "one_of_the_above_methods";
      webview.loadUrl("https://drive.google.com/viewerng/viewer?embedded=true&amp;url=" + pdf);
  </code></pre>
  
  <p>What am I doing wrong? Is there a better way to load a local pdf inside my app without having it take up the entire activity page?</p>