Misca
Misca

Reputation: 469

loadData tries to use data as url in webview

page = "<!DOCTYPE HTML><html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" +
                    "</head><body>" + page + "</body></html>";
            webContent.loadData(page, "text/html;charset=UTF-8", "UTF-8");

On the call to loadData the webview gives "URL is invalid", in the onReceivedError callback the url is "data:text/html;charset=UTF-8;UTF-8,%3C!DOCTYPE%20HTML%3E .... /body%3E%3C/html%3E". This doesn't happen on all the data I load.

Note:

Thank you!

Upvotes: 5

Views: 4209

Answers (3)

WHDeveloper
WHDeveloper

Reputation: 333

I don't know if it helps but you could try to change this line:

webContent.loadData(page, "text/html;charset=UTF-8", "UTF-8");

to this:

webContent.loadData(page, "text/html", "UTF-8");

because you already defined the charset in the call

Upvotes: 1

shireasha
shireasha

Reputation: 151

To load url you can use the code as

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");

I think below link is helpful

webview in android

Upvotes: 2

sherpya
sherpya

Reputation: 4936

webContent.loadDataWithBaseURL(null, page, "text/html", "UTF-8")

works for me, while with loadData() I get sometimes your problem

Upvotes: 8

Related Questions