1

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.

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.

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:

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url != null && url.toLowerCase().contains(".pdf")) {
        url = "http://docs.google.com/gview?embedded=true&url=" + url;
    }
    view.loadUrl(url);
    return true;
}

Here are the WebView settings we're using, if needed:

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);

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):

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&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=https://docs.google.com/gview?embedded=true&url=http://<LINK_TO_PDF_FILE>.pdf

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.

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.

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):

08-29 00:01:45.821  14306-14306/com.myapp.mobile E/url﹕ http://docs.google.com/gview?embedded=true&url=http://<LINK_TO_PDF_FILE>.pdf

Any advice would be greatly appreciated!

svguerin3
  • 2,433
  • 3
  • 29
  • 53

1 Answers1

1

There is a solution to this that we found, although not very elegant. We still don't know the root cause, but adding in the code below ensures that it won't append the "docs.google.com" to the URL more than once, if this method is called multiple times (which it is doing, apparently, for some reason on some devices):

if (url != null && url.toLowerCase().contains(".pdf") && !url.toLowerCase().contains("docs.google.com")) {
        url = "https://docs.google.com/gview?embedded=true&url=" + url;
}
svguerin3
  • 2,433
  • 3
  • 29
  • 53