public class EmojiCompat
extends Object

   ↳ androidx.emoji2.text.EmojiCompat

Main class to keep Android devices up to date with the newest emojis by adding EmojiSpans to a given CharSequence.

By default, EmojiCompat is initialized by EmojiCompatInitializer, which performs deferred font loading to avoid potential app startup delays. The default behavior is to load the font shortly after the first Activity resumes. EmojiCompatInitializer will configure EmojiCompat to use the system emoji font provider via DefaultEmojiCompatConfig and always creates a new background thread for font loading.

EmojiCompat will only allow one instance to be initialized and any calls to init(Config) after the first one will have no effect. As a result, configuration options may not be provided when using EmojiCompatInitializer. To provide a custom configuration, disable EmojiCompatInitializer in the manifest with:

When not using EmojiCompatInitializer, EmojiCompat must to be initialized manually using init(EmojiCompat.Config). It is recommended to make the initialization as early as possible in your app, such as from Application.onCreate().

init(Config) is fast and may be called from the main thread on the path to displaying the first activity. However, loading the emoji font takes significant resources on a background thread, so it is suggested to use LOAD_STRATEGY_MANUAL in all manual configurations to defer font loading until after the first screen displays. Font loading may be started by calling load()}. See the implementation EmojiCompatInitializer for ideas when building a manual configuration.

After initialization the get() function can be used to get the configured instance and the process(CharSequence) function can be used to update a CharSequence with emoji EmojiSpans.

CharSequence processedSequence = EmojiCompat.get().process("some string")

During loading information about emojis is not available. Before the EmojiCompat instance has finished loading, calls to functions such as process(CharSequence) will throw an exception. It is safe to call process when getLoadState() returns LOAD_STATE_SUCCEEDED. To register a callback when loading completes use EmojiCompat.InitCallback.


Nested classes

class EmojiCompat.Config

Configuration class for EmojiCompat. 

interface EmojiCompat.GlyphChecker

Interface to check if a given emoji exists on the system. 

class EmojiCompat.InitCallback

Listener class for the initialization of the EmojiCompat. 

interface EmojiCompat.MetadataRepoLoader

Interface to load emoji metadata. 

class EmojiCompat.MetadataRepoLoaderCallback

Callback to inform EmojiCompat about the state of the metadata load. 



Key in EditorInfo.extras that represents the emoji metadata version used by the widget.


Key in EditorInfo.extras that represents EmojiCompat.Config.setReplaceAll(boolean) configuration parameter.


Result of getEmojiMatch(CharSequence, int) that means the full codepoint sequence is not known to emojicompat, but at least one subsequence is an emoji that is known at this metadata level.


Result of getEmojiMatch(CharSequence, int) that means this codepoint can be drawn by an EmojiSpan at this metadata level.


Result of getEmojiMatch(CharSequence, int) that means no part of this codepoint sequence will ever generate an EmojiSpan at the requested metadata level.


EmojiCompat instance is constructed, however the initialization did not start yet.


An unrecoverable error occurred during initialization of EmojiCompat.


EmojiCompat is initializing.


EmojiCompat successfully initialized.


EmojiCompat will start loading metadata when init(Config) is called.


EmojiCompat will wait for load() to be called by developer in order to start loading metadata.


Replace strategy to add EmojiSpans for all emoji that were found.


Replace strategy that uses the value given in EmojiCompat.Config.


Replace strategy to add EmojiSpans only for emoji that do not exist in the system.

Public methods

static EmojiCompat get()

Return singleton EmojiCompat instance.

String getAssetSignature()

Returns signature for the currently loaded emoji assets.

int getEmojiMatch(CharSequence sequence, int metadataVersion)

Attempts to lookup the entire sequence at the specified metadata version and returns what the runtime match behavior would be.

int getLoadState()

Returns loading state of the EmojiCompat instance.

static boolean handleDeleteSurroundingText(InputConnection inputConnection, Editable editable, int beforeLength, int afterLength, boolean inCodePoints)

Handles deleteSurroundingText commands from InputConnection and tries to delete an EmojiSpan from an Editable.

static boolean handleOnKeyDown(Editable editable, int keyCode, KeyEvent event)

Handles onKeyDown commands from a KeyListener and if keyCode is one of KeyEvent.KEYCODE_DEL or KeyEvent.KEYCODE_FORWARD_DEL it tries to delete an EmojiSpan from an Editable.

boolean hasEmojiGlyph(CharSequence sequence)

This method is deprecated. use getEmojiMatch which returns more accurate lookup information.