Android 4.4 KitKat上的shouldInterceptRequest

Mar*_*inR 5 url android webview android-4.4-kitkat

我有一个应用程序,它使用Android WebViewClient中的自定义方案,shouldInterceptRequest(WebView view, String url)shouldOverrideUrlLoading(WebView view, String url)拦截Web应用程序中的请求,并使用本机库从其他地方获取资源shouldInterceptRequest.在Android 4.4 KitKat之前,这已经很好了,Google已经对webView组件进行了一些重要的更改.

http://developer.android.com/guide/webapps/migrating.html#URLs

现在收到的网址shouldOverrideUrlLoading突然变得无效,看起来像这样; 定制方案:////my.pathname.com/.首先我怀疑额外的斜杠是因为Android不认为url是有效的RFC3986,但是在一系列资源提取(css,js,images)中,url开始正确并突然变为无效格式.Android 4.3中的webView将url正确保存为custom-scheme://my.pathname.com/.看起来基本网址突然变为'/'而不是'my.pathname.com'.

然后我的注意力转移到webView 4.4迁移指南中讨论的事实:

如果从应用程序的UI线程以外的任何线程调用WebView上的方法,则可能会导致意外结果.http://developer.android.com/guide/webapps/migrating.html#Threads

这也可能是我所经历的,但我还没有提出一个解决方案,我可以使用runOnUiThread()本机api获取数据并将其返回到webView内部shouldInterceptRequest.有没有人经历类似的事情?

这是我的shouldInterceptRequest代码的简化版本:

    @Override
    public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        if (urlStartsWithKnownPrefix(url)) {
            UrlFetchResult fetchRes = api.fetchUrl(url);
            String charset = "utf-8";
            String mime = fetchRes.getMimetype();
            WebResourceResponse res = new WebResourceResponse(mime, charset, new ByteArrayInputStream(fetchRes.getResult()));
            return res;
        }
        return null;
    }
Run Code Online (Sandbox Code Playgroud)

mar*_*iba 2

您是否使用过 jquery-mobile?这听起来非常类似于:How can I userelative urls in ajax requests inside trigger.io apps on Android 4.4 (kitkat)?