Can any one please tell which other characters need to be converted before loading the data in webview.
view.loadDataWithBaseURL("data:",htmlString, "text/html",
"utf-8", htmlString);
Try ("data://", htmlString, "text/html", "utf-8", null).
That should load, although the back button behavior might not be correct.
Related
I use webview to load local html data like this
webview.loadDataWithBaseURL("about:blank", finalSrc, "text/html", "UTF-8", null);
the finalSrc is a variable of html string.
sometimes, the webview can display the corrent content,but sometimes not.
and I found that if I clear the cache of my app, the webview works well again.
so what's wrong with my app?
rather than using BaseUrl why don't use loadData. for example
webview.loadData(finalSrc, "text/html", "UTF-8");
I have a same problem like
this
Problem gets solved with loadData()
But it doesnt works with loadDataWithBaseURL()
v.loadDataWithBaseURL("file:///android_asset/index/",htmlDocument, "text/HTML", "UTF-8",null);
Please help..
OK i got it...
its simple we just need to change HTML to html i.e.(Capital to small letters)
Try something like this:
webView.loadDataWithBaseURL(null, "<body><font size='+2'>My text</font></body>", "text/html", "utf-8", null);
You can simply use
mWebView.loadUrl("file:///android_asset/privacy.html");
I had Database in which data stored in hindi as \u092e\u0948\u0902 \u0924\ and setting that content to webview using below.
webview1.loadData(hindi_content, "text/html", "UTF-8");
But it will display as
I don't know why that's happening. Any one please suggest. how to fix that !
This happens because of a bug with the encoding parameter of loadData in most Android versions. This parameter is ignored for some reason so the UTF-8 based hindi characters will not be rendered.
To fix this you can use one of the following alternatives.
webview1.loadData(hindi_content, "text/html; charset=UTF-8", null);
webview1.loadDataWithBaseURL(null, hindi_content, "text/html", "utf-8", null);
This is a duplicate of this answer:
You will also need to unescape those sequences and to do that refer to How to Unescape Unicode in Java
Rendering UTF-8 in a WebView using loadData has been broken in some form or fashion forever.
Issue 1733
Use loadDataWithBaseURL instead of loadData.
// Pretend this is an html document with those three characters
String scandinavianCharacters = "øæå";
// Won't render correctly
webView.loadData(scandinavianCharacters, "text/html", "UTF-8");
// Will render correctly
webView.loadDataWithBaseURL(null, scandinavianCharacters, "text/html", "UTF-8", null);
Now the part that is truly annoying is that on the Samsung Galaxy S II (4.0.3) loadData() works just fine, but testing on the Galaxy Nexus (4.0.2) the multi-byte characters are garbled unless you use loadDataWithBaseURL(). WebView Documentation
you will need to use font in order to support hindi (Hindi language is not yet fully supported by android)
create Singleton instance of Typeface and invoke createFromAsset();
and add it to WebSettings like this
WebSettings webSettings = webView.getSettings();
webSettings.setFixedFontFamily(InstaceOFTypeFace);
Finally I have come up with the solution of Loading hindi content to the webview.
I had simply change my loading string and unfortunately it will work.
webview.loadData(Hindi_css, "text/html; charset=UTF-8", null);
Thank you all for your effort. :)
You can use this one also.
String uri= Uri.encode(html file/url);
webView.loadUrl(uri);
may be this will help you.
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);
Actually thanks for #Viraj for the answer.
Google currently deprecated the above and you should use this instead:
webView.loadData(URLEncoder.encode(mAdvertisement.getContent(), "UTF-8").replaceAll("\\+", " "), "text/html", "UTF-8");
How can I show turkish chars (ş, ğ, ü ...) in webview as loadData?
My webview is: mWebView.loadData(detailsHtml, "text/html", "UTF-8");
thanks.
webView.loadData(htmlStr, "text/html; charset=utf-8", null);
This line of code saved me to deal with turkish character set. I hope it helps others too.
Try this code
mWebView.loadDataWithBaseURL(null,"ş, ğ, ü ","text/html", "UTF-8", null);