How to convert string to unicode in android

I am parsing some unicodes from json into my android application, api gives unicodes icons like \ue600 . When I add this unicode directly to textview as textview.setText("\ue600"); It gives the icon on the right of the textview . but when i parse this unicode from json api and then i setText that unicode it just displays \ue600 on textview . How do I parse or convert these lines to unicodes to get the icons in a textview .

thanks

+5
source share
5 answers

Convert unicode to this format  and then use this in textview textview.setText(Html.fromHtml(your_unicode_here)); It should work.

+4
source

StringEscapeUtils does most of the work, but only up to HTML4. For unreached characters, you can create your own class and add as needed. Here is an example class

 public class HTMLDecoder { public static String decodeHTML(String html) { String out = StringEscapeUtils.unescapeHtml4(html); out = out.replaceAll("ร‚ยฎ", "ยฎ"); out = out.replaceAll("รข\u0084ยข", "โ„ข"); return out; } } 

Add to build.bradle

 compile 'org.apache.commons:commons-lang3:3.0' 
+1
source

The following works great for me.

 String unicode = "\u0048\u0065\u006C\u006C\u006F"; String Title = StringEscapeUtils.unescapeJava(unicode); System.out.println(Title); 

and add the dependency: compile 'commons-lang:commons-lang:2.6' in your build.gradle file.

+1
source

How do you parse JSON data? If you use Gson , you can use GsonBuilder.disableHtmlEscaping () to display the correct characters instead of their code.

0
source
 textview.setText(Html.fromHtml(UNICODE_CHARS)); 
0
source

Source: https://habr.com/ru/post/1212816/


All Articles