Android 12 Developer Preview is here! Try it out, and give us your feedback!

EmojiCompat

@AnyThread open class EmojiCompat
kotlin.Any
   ↳ androidx.emoji.text.EmojiCompat

Main class to keep Android devices up to date with the newest emojis by adding EmojiSpans to a given . It is a singleton class that can be configured using a instance.

EmojiCompat has to be initialized using init(EmojiCompat.Config) function before it can process a CharSequence.
<code>EmojiCompat.init(/* a config instance */);</code>

It is suggested to make the initialization as early as possible in your app. Please check for more configuration parameters. Once init(EmojiCompat.Config) is called a singleton instance will be created. Any call after that will not create a new instance and will return immediately.

During initialization information about emojis is loaded on a background thread. Before the EmojiCompat instance is initialized, calls to functions such as will throw an exception. You can use the InitCallback class to be informed about the state of initialization.

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.

<code>CharSequence processedSequence = EmojiCompat.get().process("some string")</code>

Summary

Nested classes
abstract

Configuration class for EmojiCompat.

abstract

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

abstract

Listener class for the initialization of the EmojiCompat.

abstract

Interface to load emoji metadata.

abstract

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

Constants
static String

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

static String

Key in EditorInfo#extras that represents configuration parameter.

static Int

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

static Int

An unrecoverable error occurred during initialization of EmojiCompat.

static Int

EmojiCompat is initializing.

static Int

EmojiCompat successfully initialized.

static Int

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

static Int

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

static Int

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

static Int

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

static Int

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

Public methods
open static EmojiCompat!
get()

Return singleton EmojiCompat instance.

open String

Returns signature for the currently loaded emoji assets.

open Int

Returns loading state of the EmojiCompat instance.

open static Boolean
handleDeleteSurroundingText(@NonNull inputConnection: InputConnection, @NonNull editable: Editable, @IntRange(0) beforeLength: Int, @IntRange(0) afterLength: Int, inCodePoints: Boolean)

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

open static Boolean
handleOnKeyDown(@NonNull editable: Editable, keyCode: Int, event: KeyEvent!)

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.

open Boolean
hasEmojiGlyph(@NonNull sequence: CharSequence)

Returns true if EmojiCompat is capable of rendering an emoji.

open Boolean
hasEmojiGlyph(@NonNull sequence: CharSequence, @IntRange(0) metadataVersion: Int)

Returns true if EmojiCompat is capable of rendering an emoji at the given metadata version.

open static EmojiCompat!
init(@NonNull config: EmojiCompat.Config)

Initialize the singleton instance with a configuration.

open Unit

When Config#setMetadataLoadStrategy(int) is set to LOAD_STRATEGY_MANUAL, this function starts loading the metadata.

open CharSequence!
process(@NonNull charSequence: CharSequence)

Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found.

open CharSequence!
process(@NonNull charSequence: CharSequence, @IntRange(0) start: Int, @IntRange(0) end: Int)

Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found.

open