我需要在应用程序加载的网页(通过 WebView
容器)中捕获格式错误的链接 (没有“http://”)
并正确格式化它们 (adding "http://")
我通过覆盖
public boolean shouldOverrideUrlLoading(WebView view, String url).
if(url.startsWith("/")){
url = "http://www.domain.com" + url;
}
一切都很好,但我意识到在 API 19 中它无法根据 to this guide 调用 shouldOverrideUrlLoading
方法.
但是他们没有说要调用哪个方法来决定它是有效的还是无效的 url。
诸如从页面加载所有 Web 内容、查找并替换格式错误的链接然后加载该"new"页面等解决方案似乎付出了很大的努力。
有谁知道要覆盖什么方法(拦截来自 WebView 的点击)?
最佳答案
Google 有一些 documentation关于 KitKat 中的 shouldOverrideUrlLoading()
:
The new WebView applies additional restrictions when requesting resources and resolving links that use a custom URL scheme. For example, if you implement callbacks such as shouldOverrideUrlLoading() or shouldInterceptRequest(), then WebView invokes them only for valid URLs.
If you are using a custom URL scheme or a base URL and notice that your app is receiving fewer calls to these callbacks or failing to load resources on Android 4.4, ensure that the requests specify valid URLs that conform to RFC 3986.
关于android - WebView shouldOverrideUrlLoading 未在 API 19 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23007413/