我一直在为许多拥有移动网站的公司开发混合应用程序 . 事实上,有一些使用jsp制作的网站 .

我已经知道iframes和javascripts xhr请求不会触发webViewClient的shouldOverrideUrlLoading覆盖函数 . 我很好 .

但是今天我学到了一些行为,比如:

  • JSP页面重定向

  • 链接JSP页面中的单击

  • JSP / JS引发的URL加载

不会总是解雇这个功能 .

因此,当要求webView加载无法加载的页面(即“intent:// ...”)时,shouldOverrideUrlLoading()不会触发,它会显示错误页面 .

有没有人遇到过这种行为,是否有任何解决方案可以解决它?

下面是我用来调用活动的代码,其中url使用'intent:'协议(这将失败,因为执行上述操作时永远不会调用此函数)

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // ... omitted ...
        if ( url.startsWith("intent:") ) {
            Intent intent = null;
            try {
                intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                // The following flags launch the app outside the current app
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                try {
                    getActivity().startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    e.printStackTrace();
                }
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            return true;
        }
}

PS . 请注意,每个其他网站的页面加载将完美地调用shouldOverrideUrlLoading() . 我在android webViews上找不到任何JSP相关的bug,所以我问一个 .

PS . 我很乐意提供一些优雅的读者会尝试的样本网站..但该网站是用韩文写的,所以我怀疑它会有所帮助 .

谢谢!