2017-02-15 71 views
1

在我的网页浏览式的应用程序,当应用程序访问http://mobile.nytimes.com/我WebViewClient接收6-7 onPageFinished(),第3-4 WebView.getUrl()返回原来的URL(http://mobile.nytimes.com/),但随后返回“数据显示:text/html的”对于其余的。当URL是“data:text/html”时如何避免MalformedURLException?

显然,data:text/htmlvalid URI。另见https://url.spec.whatwg.org/#fetch-scheme

然而,在我的代码,我需要实例从的WebView网址的URL是这样的:

new URL(myWebView.getUrl()); 

,不幸的是,这将引发一个MalformedURLException的时候WebView.getUrl()返回 '数据:text/html的'。

有没有办法将'data:text/html'字符串转换为有效的URL字符串,以便new URL()不会抛出MalformedURLException

回答