- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个应用程序在 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/
我有 webView 覆盖了 shouldInterceptRequest 方法: @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override
我想创建一个 Intranet 应用程序。这个应用程序将显示内容,通常只能在我们的内部环境中访问。例如http://intranet.ourfirm.com 现在我们可以从外部访问此内容例如https
我想拦截 WebViewClient 中的所有 HTTP 请求并发出我自己的请求。我遇到的问题是处理压缩响应。 有几个不同的帖子建议可行的方法(例如 AndroidHttpClient.getUngz
虽然这个问题已被问过多次,但真正与我的问题相关的唯一问题是这个 ( Can I use shouldInterceptRequest to block a particular call in And
我正在尝试集成一个 javascript 插件,该插件通过使用 XmlHttpRequest 调用来加载一些资源。我希望此脚本在 WebView 的本地加载页面中运行。正如您可能已经猜到的那样,Xml
我正在尝试拦截并停止加载 webView 上的所有 mp4 视频,因为我正在使用 shouldInterceptRequest。我能够拦截视频,例如:显示一个对话框,但是我无法停止加载它们,知道为什么
我想在特定时间缓存 WebView 中显示的图像,例如7 天,所以我需要将图像缓存保存到磁盘并从磁盘加载它们并将它们提供给 WebView。 我还需要调整图像的大小以避免 WebView;内存使用率高
我在 Android WebView 上玩得很开心。 我用它来显示登录屏幕,然后在响应时拦截授权代码。应该很简单... 如果我只覆盖 shouldOverrideUrlLoading 但如果我覆盖(就
请告诉我方法 public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)
我在 Android (KitKat) 上使用 WevView,我正在尝试覆盖 shouldInterceptRequest() 并发出我自己的 HTTP 请求 - 让我的应用而不是 webview
我使用了下面的代码 public WebResourceResponse shouldInterceptRequest(WebView view, String url) { alertsav
我正在尝试拦截来自 WebView 的请求,以便我可以注入(inject)额外的 header 。我正在将 WebViewClient 应用于 WebView 并覆盖 shouldInterceptR
在 API21 中,Google 修改了 shouldInterceptRequest 方法以使用 WebResourceRequest 请求 而不是 String url。有什么方法可以编写一个扩展
目标: 覆盖 WebView 发出的所有请求并自己发出请求(最终设置代理)。 代码: @Override public WebResourceResponse shouldInterceptReque
我正在使用 Xamarin 开发一个混合 Android 应用程序,但遇到了问题。我正在使用 webview 和自定义路由引擎来服务器 Razor 页面。这一切都工作正常。我的问题是 jQuery g
我在 android 中使用 webview 创建了一个网络浏览器。我的目标是在加载之前控制 webview 的内容。每当 webview 的内容向任何域服务器发出请求时,它都必须通过 shoulIn
我的 Android 应用程序在 WebView 中显示 html5 电子书。 我有一个压缩文件,其中包含一本电子书及其所有资源:文本、图像和音频(mp3 文件)。 为了解压本书,我使用了 shoul
我有一个应用程序在 Android WebViewClient 的 shouldInterceptRequest(WebView view, String url) 和 shouldOverrideU
我正在使用 shouldInterceptRequest 拦截来自 webview 的请求 下面是我返回 WebResourceResponse 的代码 @TargetApi(Build.VERSIO
我想在 webview 中为请求添加自定义 header 。我认为应该可以在 shouldInterceptRequest 中完成。因为我的最低 API 级别低于 21 shouldIntercept
我是一名优秀的程序员,十分优秀!