Android Jetpack: EmojiCompat
Articles Blog

Android Jetpack: EmojiCompat

August 24, 2019

Have you seen this sad blank square
character called tofu when an app can’t display an emoji? New emojis are constantly being
added to the Unicode standards. But since they are
bundled as a font, your phone’s emojis are set
in stone with each OS release. Well, they were. With the Emoji Compact
Library, part of Jetpack, your app can get backwards
compatible emoji support on devices with API level 19
and higher, and get rid of tofu. For a given char
sequence, Emoji Compact can identify the emojis,
replace them with emoji spans, and then render the glyphs. On versions prior
to API level 19, well, you’ll still get
the tofu characters. Emoji Compact builds on the
downloadable font mechanism to make sure that
you always have the latest emoji available. So if you want the emoji font
to be downloaded when you’re installed from Play Store, add
this metadata in your manifest, like this. The font will be
downloaded, and ready to be used when your app
starts for the first time. Before being used, the
Emoji Compact library needs a one time
asynchronous setup. We recommend doing this
in your launch activity, or in the first activity
that uses emojis, like this. When using the downloadable
font configuration, create your form
request, and create the
fontRequestEmojiCompactConfig object. If you can’t use
downloadable fonts, then you can bundle the
emoji font like this. Note that the size of the
font is multiple megabytes, increasing your APK
size considerably. On top of this, you will have
to ship updates of your app whenever the emoji
font is updated. Independent of the
way you’re using it, the initialization takes
at least 150 milliseconds, even up to a few seconds. So you might want to get
notified about this state. For this, use the
registerInitCallback method. Here’s a pro tip for debugging. You can enable a span
indicator like this. Display emojis by using
widgets that extend from app compact widgets. You can preprocess
a char sequence using the process method. It can then reuse
the result instead of the initial raw
string in any widget that can render spanned
instances, and needs to display the same string. So, for example, if you are
doing your own custom drawing, you can use this to
display emoji text. If you want to add emoji
support to a TextView subclass beyond the provided ones,
for example, to an AppCompact checkbox, you can use the
emojiTextViewHelper class. So now, with the new
Emoji Compact Library, I can see that my
friend isn’t asking me if I want tofu for
brunch, but avocados. And the answer for this
is, of course, yes. [ROCKET SOARING]

Only registered users can comment.

  1. Hey my question is
    I thinking is i give android associated developer exam.
    But more quarries like whats a job guaranty, how many time validity and more.
    I also apply job at google but no replay please give me details whats study requirements for apply job at google
    I am electronics student but my hobby is coding
    You need to know more about me please you visit is my blog or website

  2. Hi, do you have any idea why Google drawings and Google slides cannot download a displayed emoji into a jpg or png many thanks I made this today

  3. Whenever I run on app with ask/API that is 23 or lower it crashes instantly die to EmojiTextView. Can anyone help me?

Leave a Reply

Your email address will not be published. Required fields are marked *