Search code examples
androidtextviewemoji

How to set unicode in textview to show emoji in android?


I am getting some Unicode string(emoji icons) from server in json string format.

My problem is strange and I am trying for last two days to resolve this issue. When I parse json and store all the Unicode string in an ArrayList<String> and try to set the text on TextView by getting value from the same ArrayList then it shows Unicode characters as :

Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3

and when the same string I set on textview by passing static value as : textview.settext("Ghcghchgc\ud83d\ude03\ud83d\ude03fyju\ud83d\ude0c6\u20e3")

then the textview is showing perfect emojis.

I am stuck at this point. Can anybody please help me to resolve this issue or tell me if I am doing something wrong.


Solution

  • This sounds like you want to unescape your string that you've got from JSON. If you don't mind adding a library, Apache Commons has a String.unescapeJava function which does what you need. If you don't want to add that library, see this answer.