Android WebView doesn't shows some characters "ṭ ḍ ḥ" - android

Some of the not-show characters:
ḍ - ḍ
ḥ - ḥ
ḫ - ḫ
ḳ - ḳ
All the characters that not shown in Android WebView, HTML Entity's are greater than 7000.
I tried the solution below but it didn't work.
WebSettings settings = myWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
myWebView.loadDataWithBaseURL(null, "#ḍḥḳ#", "text/html", "utf-8", null);
It showed in WebView : " "
I'll be very thankful for any advice.

Using entities for such symbols isn't best idea at all.
You should use UTF-8, which can hold virtually any character. For solution, you've showed (that doesn't seem to work) -- make yourself sure, that either document content or string, you're passing is actually encoded in UTF-8. It's not just setting the encoding, but actually encoding correctly the file as well.
And don't mix up entities with UTF-8. Either use one or another solution to encode special characters.

Related

Webview doesn't display text with color

In my app I display some Html content in webview:
String webViewConent = 'this is some <span style="color:#2ecc71">sample</span> string'
webView.loadData(omowienie, "text/html; charset=utf-8", "UTF-8");
However after last app update, which was related with some other thing, for some users webview doesn't work correctly. They see only string which is before span tag. The problem is not related to any specific android version.
Same problem here, I found base64 encoding as a quick fix:
String base64 = android.util.Base64.encodeToString(html.getBytes("UTF-8"), android.util.Base64.DEFAULT);
mWebView.loadData(base64, "text/html; charset=utf-8", "base64");
I had the same issue today. As a simple workaround I replaced hex colors in CSS by RGB equivalents.
Before
<span style="color: #3050c0">Some text</span>
After
<span style="color: rgb(48, 80, 192)">Some text</span>
I found the approach in this answer on WebView encoding seems to fix this issue. Instead of using loadData, try loadDataWithBaseURL:
webview.loadDataWithBaseURL(null, html, "text/html; charset=utf-8", "utf8", null)
I have same problem. My app does not display text after span tag. Some devices works fine but some devices does not work. Upvoted!
<p><span style="color:#0000CD"><strong>Materials:</strong></span></p>
As a result of my research and experimentation, I have disabled the Android System Webview application on my device. As a result of this process, my application worked correctly. However, to me, this cannot be a solution. What are your ideas?
I think the problem is the new update in Android Webview System. The old version works for me.
My alternative solution here is to uninstall Android Webview System in your phone so that you can have the default version(this solution is not ideal if your app is uploaded in Google Playstore and have a lot of users)
The second option is you can delete your color and background color codes in html for the meantime and it will work(I think it is Android Webview System's bug and we just need to wait until they fix their issues)
I have same problem. It may be the Android WebView System's bug but the solution is using font tag to color the texts.
String webViewConent = "this is some <font style="color:green">sample</font> string";
Note : This code is not working for Hex format colors
I din't find a fix but I was able to do a work around changing the string with the original HTML. This might help someone else, AS LONG AS YOU ALREADY KNOW THE COLOURS YOUR ARE GOING TO DISPLAY:
String newString = originalString.replaceAll("color:#888888", "color:gray");

Android application: wrong charset of server content

One of our application's users says that he cannot read news comment because of wrong symbols charset. He has Galaxy Ace Duos (GT-S6802) and made a screenshot:
Nobody else complains about the error. What could be the problem?
The app loads comments (UTF-8) from server API. Text of each comment has html format (contains images) and therefore is placed in a WebView this way:
holder.text.loadData(text, "text/html; charset=UTF-8", "utf-8");
App on Play Market: https://play.google.com/store/apps/details?id=kz.sportlive
I solved my problem. But before it I tried to encode comment text to Base64 on server and decode it on app - didn't work.
Then I tried load encoded text in WebView:
webview.loadData(comment.text_base64, "text/html; charset=UTF-8", "base64");
It didn't work too.
Finally I tried this way:
webview.getSettings().setDefaultTextEncodingName("utf-8");
webview.loadData(comment.text, "text/html; charset=utf-8", null);
and it works perfect!
Use it in similar situations

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.

Android - Characters such as å,ä,ö do not render correctly in WebView

I am using the following code to render my webview in android -
webview.loadDataWithBaseURL(null, "Subject: "+ getSubject() +" Content: "+ getContent() , "text/html" , "UTF-8", "");
The subject and content that I receive from the server are UTF encoded and show wrongly as Ã¥,ä,ö in the log and on screen. However in iOS webview they show up correctly as å,ä,ö. How do I get them to show as å,ä,ö in android as well?
make sure the content you recieve, in tag <head> use like this: <meta charset="UTF-8" >
Sorry for my English. :)
I think it's more of a font problem than code itself. Try putting DejaVuSans.ttf font instead of DroidSansFallback.ttf on the android itself. It should fix it. I'd search forum.xda-developers.com for a solution.
It was due to how I was retrieving the message from the server. I was reading the Http response character by character so it broke up the encoding. When I started reading line by line it worked fine!

How to programmatically set / edit content of webview

Is there a way I can edit the content either to add to or create from scratch via the java? I haven't been able to find any examples.
You should look at the WebView documentation here.
Among other great bits of information there, you'll find:
// OR, you can also load from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html; charset=utf-8", "utf-8");
// ... although note that there are restrictions on what this HTML can do.
// See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.
very close to the top of the page.
WebView.loadData can be passed a straight HTML string. I use a "page" i create from scratch in my app that is just formatted with HTML

Categories

Resources