title: Android WebView - Redirect issue using Google Docs to open PDF
body: <p>I have a strange issue that only seems to be happening on a few physical devices (Nexus 4, Nexus 7), all running the latest Android OS.  I cannot reproduce it on my older LG test phone, nor can I reproduce it in any Genymotion simulator I'm using; I've tried all kinds of API levels and all kinds of simulator devices, and it just never occurs in the simulator.</p>
  
  <p>The issue is that when a PDF url is called (using Google Docs to load it), it appears to just re-direct over and over again, eventually failing.  I'm not sure if that's what's actually happening behind the scenes, but it's how it appears.</p>
  
  <p>We have WebViewClient code to intercept the URL and change/load it appropriately if the URL contains ".pdf".  Here is the Java code for that:</p>
  
  <pre><code>@Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
      if (url != null &amp;&amp; url.toLowerCase().contains(".pdf")) {
          url = "http://docs.google.com/gview?embedded=true&amp;url=" + url;
      }
      view.loadUrl(url);
      return true;
  }
  </code></pre>
  
  <p>Here are the WebView settings we're using, if needed:</p>
  
  <pre><code>webview.getSettings().setJavaScriptEnabled(true);
  webview.getSettings().setPluginState(null);
  webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
  webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
  webview.getSettings().setPluginState(PluginState.ON);
  webview.getSettings().setLoadWithOverviewMode(true);
  webview.getSettings().setUseWideViewPort(true);
  webview.getSettings().setSupportZoom(true);
  webview.getSettings().setAppCacheEnabled(true);
  webview.clearCache(false);
  webview.getSettings().setBuiltInZoomControls(true);
  </code></pre>
  
  <p>In the logs, we are seeing this being printed over and over when the webview is trying to load (on the devices where this fails):</p>
  
  <pre><code>08-27 17:28:35.135  10460-10460/com.myapp.mobile W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid: 10460
  08-27 17:28:35.135  10460-10460/com.myapp.mobile E/url﹕ https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=https://docs.google.com/gview?embedded=true&amp;url=http://&lt;LINK_TO_PDF_FILE&gt;.pdf
  </code></pre>
  
  <p>I'm not sure why it's appending that Google Docs URL over and over and over again, but I suspect that's part of the problem.  We are suspecting that perhaps the app is trying to use Google Drive or something to open it as well, but we are not 100% there.  I'm just not sure why some devices this works fine but a lot of them it does not work.  </p>
  
  <p>Any thoughts on ways to debug this?  I'm guessing I may need to go about the shouldOverrideUrlLoading() method a little differently, but I'm a bit stumped as to what to do there.  Perhaps the view.loadUrl() line is causing that method to be called over and over again, but that still has me a bit stumped as to why it's working on some and not working on other devices.</p>
  
  <p>Not sure it matters, but I get this one line printed in the logs even when running in the simulator (even though the website pulls up fine):</p>
  
  <pre><code>08-29 00:01:45.821  14306-14306/com.myapp.mobile E/url﹕ http://docs.google.com/gview?embedded=true&amp;url=http://&lt;LINK_TO_PDF_FILE&gt;.pdf
  </code></pre>
  
  <p>Any advice would be greatly appreciated!</p>