Android WebView(4.4)转换自定义URL [英] Android WebView (4.4) Converts Custom URL

查看:106
本文介绍了Android WebView(4.4)转换自定义URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序大量使用Android WebView来显示我的自定义HTML内容.最新的Android更新(4.4/Kit-Kat/SDK-19)具有重新设计的WebView.

I have an app that heavily uses the Android WebView to display my custom HTML content. The latest Android update (4.4/Kit-Kat/SDK-19) featured a redesigned WebView.

我的一位使用Nexus 5的用户报告了一个问题,其中某些链接导致该应用崩溃.我在4.4仿真器中运行并调试到WebViewClientshouldOverrideUrlLoading()方法.在所有先前测试的Android版本(2.2-4.3)上,传递给该方法的URL String具有我的自定义URL,其中带有"/"字符.在4.4中,完全相同的链接现在在其位置带有"\"字符.

One of my users with a Nexus 5 reported a problem where some links cause the app to crash. I ran in the 4.4 emulator and debug into my WebViewClient's shouldOverrideUrlLoading() method. On all previously tested Android versions (2.2-4.3) the url String passed into the method had my custom url with "/" characters in it. In 4.4 the exact same link now has "\" characters in their place.

这对我来说没有任何意义.我加载的HTML完全一样,因此新的WebView将我的所有斜杠转换为反斜杠.

This doesn't make any sense to me. I load the HTML exactly the same, so somehow the new WebView converted all my slashes into backslashes.

为什么新的WebView会这样做?

Why does the new WebView do this?

推荐答案

URL处理方面的更改是一个已知问题.有关更多详细信息,请参见迁移指南.

Changes in URL handling are a known issue. Please see the migration guide for more detail.

在这种特殊情况下的行为将取决于您的基本URL方案,从您的描述来看,我猜您的基本URL方案为"http(s)://",在这种情况下,Chromium WebView会执行 URL标准化.

The behaviour in this particular case will depend on what your base URL's scheme is, from what you're describing I'm guessing your base URL's scheme is "http(s)://" in which case the Chromium WebView performs URL normalization.

您可能要考虑使用 URI类来处理在这种情况下,Classic和Chromium WebView之间存在差异.

You might want to consider using the URI class to handle the discrepancy between the Classic and Chromium WebViews in this case.

这篇关于Android WebView(4.4)转换自定义URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆