Can I check if a Unicode codepoint will be displayable under Android?

1.3k views Asked by At

My current project uses some symbols which are absent in many fonts. So far I've found some iOS renders as a box so I'm expecting sooner or later to find one that Android can't render too, though so far it's done better than iOS in this regard.

Is there a way to programatically check that a given Unicode codepoint will display correctly on the screen and not as an empty square box etc?

If I can detect a symbol can't be rendered I can implement a workaround for it rather than display an ugly box.

2

There are 2 answers

0
Siyamed On BEST ANSWER

For general unicode characters you can use PaintCompat.hasGlyph.

You should still use EmojiCompat that is mentioned in ianhanniballake's answer to be able to properly render emojis.

3
ianhanniballake On

With Emoji Compat, all current Unicode characters are supported back to API 19. It can be used with Downloadable Fonts, ensuring that as additional Unicode characters become standardized, your app automatically supports them.

You can confirm if a specific character is supported by Emoji Compat with hasEmojiGlyph():

EmojiCompat.get().hasEmojiGlyph(charSequence);

Note: you must have initialized Emoji Compat before calling this.

The EmojiCompat DevByte video shows a minimal set of steps to get things working.