I'm calling loadData
on my WebView
and passing it some HTML in the form of a String like so:
webView.loadData( htmlString, "text/html", "utf-8" );
It works fine on my Galaxy Tab 10.1, but the WebView
displays:
Webpage not available
when running on the emulator with everything set up to match my Galaxy Tab. Setting android.permission.INTERNET
in the manifest has no effect, though I shouldn't need that permission since I'm rendering in-memory HTML, and not accessing anything over the data connection.
What's going on?
Try with this code
webView.loadData( URLEncoder.encode(htmlString).replaceAll("\\+"," "), "text/html", "utf-8" );
insted of
webView.loadData( htmlString, "text/html", "utf-8" );
it should work, because sometimes character like '%', '\', '#' creates problem if its not properly Encoded
In 2.x
platforms loadData()
fails in some cases (it requires the html to be escaped), use loadDataWithBaseURL()
instead and pass null
for baseUrl
and historyUrl
:
webView.loadDataWithBaseURL(null, htmlString, "text/html", "utf-8", null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With