How to set emoji by unicode in a textview?

Gilbert Giesbert picture Gilbert Giesbert · Nov 12, 2014 · Viewed 72.9k times · Source

Hi I'd like to do the following:

??? unicode = U+1F60A
String emoji = getEmojiByUnicode(unicode)
String text = "So happy "
textview.setText(text + emoji);

to get this in my textview:

So happy 😊

How can I implement getEmojiByUnicode(unicode)?

What type should the unicode variable be? (String, char, int?)

Please note that I do NOT want to use Drawables!

Answer

Gilbert Giesbert picture Gilbert Giesbert · Nov 12, 2014

Found a solution:

In my unicode I replaced 'U+' by '0x'

Example: replace 'U+1F60A' by '0x1F60A'

This way I got an 'int' like

int unicode = 0x1F60A;

Which can be used with

public String getEmojiByUnicode(int unicode){
    return new String(Character.toChars(unicode));
}

So Textview displays 😊 without Drawable

Try it with http://apps.timwhitlock.info/emoji/tables/unicode