title: Unable to Load PDF File in the Webview
body: <p>i have a question. I developed a project with webview component but i cannot display pdf files in the webview, because in the website link all pdf files opened with new tab and pdf file is authentication with user session. I tested this website link on the Official Android Chrome app all pdf files is opened and automatically downloaded PDF files in the mobile storage but on webview component i cannot display this.
  Please could you help me for this topic. Thanks in advance.
  My code is:</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  private WebView webView = null;
  private Button button;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      this.webView = (WebView) findViewById(R.id.webview);
      CookieManager.getInstance().setAcceptCookie(true);
      this.button = (Button) findViewById(R.id.button);
  
      webView.addJavascriptInterface(new WebAppInterface(this), &quot;Android&quot;);
      WebSettings webSettings = webView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webView.getSettings().setAllowFileAccess(true);
      webView.getSettings().setDatabaseEnabled(true);
      webView.getSettings().setDomStorageEnabled(true);
      webView.getSettings().setAllowContentAccess(true);
      webView.getSettings().setDomStorageEnabled(true);
     String DESKTOP_USER_AGENT = &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36&quot;;
      webView.getSettings().setUserAgentString(DESKTOP_USER_AGENT);
  
      webView.setWebViewClient(new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
              super.onPageStarted(view, url, favicon);
          }
  
          @Override
          public void onLoadResource(WebView view, String url) {
              super.onLoadResource(view, url);
          }
  
          @SuppressLint(&quot;InlinedApi&quot;)
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
              CookieSyncManager.getInstance().sync();
  
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
  
                  CookieManager cookieManager = CookieManager.getInstance();
  
                  cookieManager.setAcceptThirdPartyCookies(webView, true);
  
              } 
  
                  Intent intent = new Intent(Intent.ACTION_VIEW);
                  Uri videoUri = Uri.parse(url);
                  intent.setDataAndType( videoUri, &quot;application/pdf&quot; );
                  intent.setPackage( &quot;com.example.webview&quot; );
                  startActivity( intent );
  
              view.loadUrl(url);
                  return true; // to tell the WebView that it should not load the URL because you handled it by yourself
  
          }
          @Override
          public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
              handler.proceed(); // Ignore SSL certificate errors
          }
  
          @Override
          public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { 
              showDefaultError();
          }
  
          @Override
          public void onPageFinished(WebView view, String url) {
  
              CookieSyncManager.getInstance().sync();
  
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {
  
                  CookieManager cookieManager = CookieManager.getInstance();
  
                  cookieManager.setAcceptThirdPartyCookies(webView, true);
  
              } 
              super.onPageFinished(view, url);
  
          }
      });
  
  webView.setWebChromeClient(new WebChromeClient() {
      @Override
      public void onProgressChanged(WebView view, int newProgress) {
  
          //put your code here if your want to show the progress with progressbar
      }
  });
  
  webView.loadUrl(“MY LINK”);
  </code></pre>