Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string into unicode in android

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

Thanks

like image 459
israr Avatar asked Feb 06 '15 15:02

israr


3 Answers

Convert your unicode into this format  & then use like this in your textview textview.setText(Html.fromHtml(your_unicode_here)); It should work.

like image 130
Husnain Aslam Avatar answered Oct 07 '22 14:10

Husnain Aslam


StringEscapeUtils does most of the work, however it only goes up to HTML4. For characters not covered you can make your own class and add as needed. Here is a sample 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'
like image 29
Adam W Avatar answered Oct 07 '22 15:10

Adam W


Following works fine for me.

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

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

like image 42
Joseph Mekwan Avatar answered Oct 07 '22 15:10

Joseph Mekwan