1

In my WebView-based app, when the app accesses http://mobile.nytimes.com/ my WebViewClient receives 6-7 onPageFinished(), the first 3-4 with WebView.getUrl() returning the original URL (http://mobile.nytimes.com/) but then it returns "data:text/html" for the rest.

Apparently, data:text/html is a valid URI. Also see https://url.spec.whatwg.org/#fetch-scheme .

However, in my code, I need to instantiate a URL from WebView's url like this:

new URL(myWebView.getUrl());

and unfortunately this throws a MalformedURLException when WebView.getUrl() returns 'data:text/html'.

Is there a way to convert the 'data:text/html' string to a valid URL string so that new URL() will not throw the MalformedURLException?

Community
  • 1
  • 1
WebViewer
  • 761
  • 7
  • 21

1 Answers1

0

As you wrote data: is a valid URI not an URL. https://en.wikipedia.org/wiki/Data_URI_scheme

Fusselchen
  • 382
  • 1
  • 4
  • 12
  • What about http://url.spec.whatwg.org/#fetch-scheme ? Also, if it's not a valid URL, why does `WebView.getUrl()` return it? – WebViewer Feb 15 '17 at 09:11