Kevin Murvie Kevin Murvie - 8 months ago 54
Android Question

Android - Shortname to Unicode from Emojione doesn't work

First of all, I don't know whether I should ask this here or in the repo, but as I saw other questions for other libraries like.. Picasso, so here goes :

I'm trying to implement Emojione into my Android app. I've downloaded a small static class to convert all short name to unicode from Emojione Github Repo.

The problem is, when I try to use it to convert :smile: to unicode..

Emojione.shortnameToUnicode(postMessageText, true); // postMessageText is ":smile:"

It always return.. A square, as if it failed to convert. I tried other short names too like :smiley:, :grinning:, but they also failed. :(something): is really a short name right?


The answer is actually in front of my eyes all the time. It really did convert to unicode but, I might be wrong here, in a font unsupported by Android. So I tried using SpannableStringBuilder to span the emoji part to use emojione-android.ttf

Here's how :

int firstEq = sb.length();
Typeface font = FontCache.getTypeface("emojione-android.ttf", context);
String convertPart = Emojione.shortnameToUnicode(part, true);
sb.append(convertPart + " ");
int lastEq = sb.length();
sb.setSpan(new CustomTypefaceSpan("", font), firstEq, lastEq, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

And that's how I got the TextView to show emojis.. Just use the font!