title: Error- Loading PDF from URL inside android Webview
body: <p>I am trying to load the PDF File from URL inside web-view without Downloading in android. Most of the time its loading perfectly ,but sometimes getting below mentioned errors.</p>
  
  <p><strong>ERROR:1</strong></p>
  
  <pre><code> ERROR:gles2_cmd_decoder.cc(2787)] [GroupMarkerNotSet(crbug.com/242999)!:B0F7473971000000] GL ERROR :GL_INVALID_FRAMEBUFFER_OPERATION : BackFramebuffer::Create: &lt;- error from previous GL command
  </code></pre>
  
  <p><strong>ERROR:2</strong></p>
  
  <pre><code>validate_display:99 error 3008 (EGL_BAD_DISPLAY)
  </code></pre>
  
  <p><strong>Code Snippet:</strong></p>
  
  <p><strong>init()</strong> method called inside On-create</p>
  
  <pre><code>private void init()
  {
      WebView webview = (WebView) findViewById(R.id.webview);
      WebSettings settings = webview.getSettings();
      settings.setJavaScriptEnabled(true);
      webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
  
      PdfWebViewClient pdfWebViewClient = new PdfWebViewClient(this, webview);
      pdfWebViewClient.loadPdfUrl(
                  "YOUR URL for Loading PDF");
  }
  </code></pre>
  
  <p><strong>PdfWebViewClient.java</strong></p>
  
  <pre><code>private class PdfWebViewClient extends WebViewClient
  {
      private static final String TAG = "PdfWebViewClient";
      private static final String PDF_EXTENSION = ".pdf";
      private static final String PDF_VIEWER_URL = "http://docs.google.com/gview?embedded=true&amp;url=";
  
      private Context mContext;
      private WebView mWebView;
      private ProgressDialog mProgressDialog;
      private boolean isLoadingPdfUrl;
  
      public PdfWebViewClient(Context context, WebView webView)
      {
          mContext = context;
          mWebView = webView;
          mWebView.setWebViewClient(this);
      }
  
      public void loadPdfUrl(String url)
      {
          mWebView.stopLoading();
  
          if (!TextUtils.isEmpty(url))
          {
              isLoadingPdfUrl = isPdfUrl(url);
              if (isLoadingPdfUrl)
              {
                  mWebView.clearHistory();
              }
  
              showProgressDialog();
          }
  
          mWebView.loadUrl(url);
      }
  
      @SuppressWarnings("deprecation")
      @Override
      public boolean shouldOverrideUrlLoading(WebView webView, String url)
      {
          return shouldOverrideUrlLoading(url);
      }
  
      @SuppressWarnings("deprecation")
      @Override
      public void onReceivedError(WebView webView, int errorCode, String description, String failingUrl)
      {
          handleError(errorCode, description.toString(), failingUrl);
      }
  
      @TargetApi(Build.VERSION_CODES.N)
      @Override
      public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest request)
      {
          final Uri uri = request.getUrl();
          return shouldOverrideUrlLoading(webView, uri.toString());
      }
  
      @TargetApi(Build.VERSION_CODES.N)
      @Override
      public void onReceivedError(final WebView webView, final WebResourceRequest request, final WebResourceError error)
      {
          final Uri uri = request.getUrl();
          handleError(error.getErrorCode(), error.getDescription().toString(), uri.toString());
      }
  
      @Override
      public void onPageFinished(final WebView view, final String url)
      {
          Log.i(TAG, "Finished loading. URL : " + url);
          dismissProgressDialog();
      }
  
      private boolean shouldOverrideUrlLoading(final String url)
      {
          Log.i(TAG, "shouldOverrideUrlLoading() URL : " + url);
  
          if (!isLoadingPdfUrl &amp;&amp; isPdfUrl(url))
          {
              mWebView.stopLoading();
  
              final String pdfUrl = PDF_VIEWER_URL + url;
  
              new Handler().postDelayed(new Runnable()
              {
                  @Override
                  public void run()
                  {
                      loadPdfUrl(pdfUrl);
                  }
              }, 300);
  
              return true;
          }
  
          return false; // Load url in the webView itself
      }
  
      private void handleError(final int errorCode, final String description, final String failingUrl)
      {
          Log.e(TAG, "Error : " + errorCode + ", " + description + " URL : " + failingUrl);
      }
  
      private void showProgressDialog()
      {
          dismissProgressDialog();
          mProgressDialog = ProgressDialog.show(mContext, "", "Loading...");
      }
  
      private void dismissProgressDialog()
      {
          if (mProgressDialog != null &amp;&amp; mProgressDialog.isShowing())
          {
              mProgressDialog.dismiss();
              mProgressDialog = null;
          }
      }
  
      private boolean isPdfUrl(String url)
      {
          if (!TextUtils.isEmpty(url))
          {
              url = url.trim();
              int lastIndex = url.toLowerCase().lastIndexOf(PDF_EXTENSION);
              if (lastIndex != -1)
              {
                  return url.substring(lastIndex).equalsIgnoreCase(PDF_EXTENSION);
              }
          }
          return false;
      }
  }
  </code></pre>