在我的基于 WebView 的应用程序中,当应用程序访问http://mobile.nytimes.com/时,我的 WebViewClient 收到 6-7 onPageFinished(),前 3-4 个WebView.getUrl( ) 返回原始 URL ( http:// /mobile.nytimes.com/),但随后返回“data:text/html”。
显然,data:text/html是一个有效的 URI。另请参阅https://url.spec.whatwg.org/#fetch-scheme。
但是,在我的代码中,我需要从 WebView 的 url 实例化一个 URL,如下所示:
new URL(myWebView.getUrl());
不幸的是,当 WebView.getUrl() 返回“data:text/html”时,这会引发 MalformedURLException。
有没有办法将 'data:text/html' 字符串转换为有效的 URL 字符串,这样new URL()
就不会抛出MalformedURLException?