android - WebView shouldOverrideUrlLoading 未在 API 19 中调用

标签 android webview

我需要在应用程序加载的网页(通过 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/

相关文章:

Android Tasker App Advance Input Shell 命令

android - Android 项目的 Jira 工作流程

android - 触摸网站中的项目或菜单时,网站无法在 WebView 上正常工作

android - 在 webview android 中截取视频的屏幕截图

Android Webview 与 Android Chrome 浏览器

java - 在选项卡式 Activity 中禁用滑动 (Android Studio)

android - 我应该如何为 Android 应用程序制作服务器端软件?

java - 覆盖Android上的删除键?

Android:在 Webview 中加载 facebook 页面

javascript - Android 4.2 股票浏览器。 Canvas clearRect() 有时不起作用