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");
Related
I am using the following code for rendering a dynamically created html string on a webview. It works properly on my device. But on one of the user's device, the webview displays the raw html tags and content instead of rendering properly.
I cannot reproduce the issue on my devices. What can be cause for this issue to happen. Any device level settings? or Encoding related issue?
String htmlContent = "<html><body> .... </body></html>";
webview.loadDataWithBaseURL(null, htmlContent, "text/HTML", "UTF-8", null);
Try this code. It works for me.
WebSettings settings = mDesc.getSettings();
settings.setDefaultTextEncodingName("utf-8");
mDesc.loadData(mDescText, "text/html; charset=utf-8",null);
Issue is goback() not showing my html data back. Steps to produce this issue is like
Loaded html data using method loadDataWithBaseURL. It renders html data fine.
Then click on one link inside html data then webview moves to next page showing that link which is also fine.
When I call method goback() from this page it should show my html data but it is showing me blank screen. Inside onPageFinished() I am getting url as about:blank.
Thanks in advance!
If you use loadDataWithBaseURL you will need to send in the url parameter something different from null, if you send null the url will always be "about:blank"
Example:
var page = new RazorView().GenerateString();
webView.LoadDataWithBaseURL("file:///android_asset/", page, "text/html", "UTF-8", "");
var url = webView.CopyBackForwardList().GetItemAtIndex(1).Url;
//url will get the Html From Previous Page
Notice im using C# but it should be the same with java, except for the CapitalizedWords
When I first create the activity, everything goes fine. However, after I choose from menu to change some text of the String values and set the webview by
webview.loadData(result, "text/html; charset=UTF-8", null);
webview.loadData(result, "text/html; charset=UTF-8", null);
I have to do it twice, or the webview will keep unchanged. Is there anyone knows what happens here? Since the result String is the same, why webview force me to loadData twice?
Avoid WebView#loadData(String data, String mimeType, String encoding) - it's buggy.
Use WebView#loadDataWithBaseURL(String baseUrl, String data, String mimeType, String encoding, String historyUrl) instead.
So your instruction will be like:
webview.loadDataWithBaseURL(null,result,"text/html", "utf-8", null);
Don't know what's your problem but looking at the webview documentation, you are using the loadData method wrongly :
Webview:loadData documentation
You probably should call your webview like this :
webview.loadData(result, "text/html", "UTF-8");
Don't know if it will solve your issue at all.
Yes with loadDataWithBaseURL it does refresh the data, but then it ignores the CSS body background-color! ... At least it can't parse "%23000000" which works with loadData.
I am loading local HTML data into my webview, and this webview is inside recyclerview,
When I try webview.loadData() when it renders 1st time it working fine, but when I scrolling upward downward every inflated webview`s get messed-up.
When I try second webview.loadDataWithBaseURL() its working like charm.
so,when you're loading the HTML locally and it references assets such as images & css which are also packaged locally use webview.loadDataWithBaseURL()
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 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);