Android webview doesnt load html file - android

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");

Related

android webview can not show content by loaddatawithbaseurl sometime

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");

Hindi Character will not display in web view correctly

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.

webView.loadDataWithBaseURL() does not work with special characters like %

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.

href from json in android xml

I have and app and on my main menu page I want to load a clickable ad (href) from json.
example :
'nationalad':
"<"img src=\"http:\/\/www.mywebsite.com\/images\/national\/fullrz_2_4e657ae4df4ee_mywebsite.JPG\">"
This is the value I am getting back from json :
"<"img src="http://www.mywebsite.com/images/national/fullrz_2_4e657ae4df4ee_kickintheapp.JPG">
How do I set this in my xml page? Do I use a view or webview or an image /image button?
Completely lost.
Use a WebView, and show the data by using loadDataWithBaseURL(null, yourData, "text/html", "utf-8", null);
Hmm this works great for the first run what when I re-run the app the webview is not showing. The only thing that changes is that the image coming in is different on each load.
webView2.loadDataWithBaseURL(null, valArray.getString(1), "text/html", "utf-8", null);

Android WebView LoadData - Turkish Chars

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);

Categories

Resources