gpt4 book ai didi

android - Android 4.4 KitKat 上的 shouldInterceptRequest

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:05:02 25 4
gpt4 key购买 nike

我有一个应用程序在 Android WebViewClient 的 shouldInterceptRequest(WebView view, String url)shouldOverrideUrlLoading(WebView view, String url) 中使用自定义方案来拦截请求Web 应用程序并使用 native 库从 shouldInterceptRequest 中的其他位置获取资源。这在 Android 4.4 KitKat 之前一直运行良好,Google 对 webView 组件进行了一些重要更改。

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

现在 shouldOverrideUrlLoading 收到的 url 突然失效了,看起来像这样;自定义方案:////my.pathname.com/。首先,我怀疑额外的斜杠是因为 Android 认为 url 不是有效的 RFC3986,但在一系列资源获取(css、js、图像)中,url 开始正确并突然变为无效格式。 Android 4.3 中的 webView 将 url 正确保存为 custom-scheme://my.pathname.com/。似乎基本 url 突然更改为“/”而不是“my.pathname.com”。

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

If you call methods on WebView from any thread other than your app's UI thread, it can cause unexpected results. http://developer.android.com/guide/webapps/migrating.html#Threads

这也可能是我正在经历的,但我还没有想出一个解决方案,我可以使用 runOnUiThread() 通过 native api 获取数据并将其返回到里面的 webView 应该拦截请求。有没有人经历过类似的事情?

这是我的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;
}

最佳答案

您有没有使用过 jquery-mobile?这听起来非常类似于:How can I use relative urls in ajax requests within trigger.io apps on Android 4.4 (kitkat)?

关于android - Android 4.4 KitKat 上的 shouldInterceptRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20289684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com