# EmojiCompat

Artifact: [androidx.emoji:emoji](https://developer.android.com/jetpack/androidx/releases/emoji) [View Source](https://cs.android.com/search?q=file:androidx/emoji/text/EmojiCompat.java+class:androidx.emoji.text.EmojiCompat) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

*** ** * ** ***


```
@AnyThread
public class EmojiCompat
```

<br />

*** ** * ** ***

Main class to keep Android devices up to date with the newest emojis by adding `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan`s to a given `https://developer.android.com/reference/java/lang/CharSequence.html`. It is a singleton class that can be configured using a `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config` instance.
EmojiCompat has to be initialized using `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.EmojiCompat.Config)` function before it can process a `https://developer.android.com/reference/java/lang/CharSequence.html`.

```
EmojiCompat.init(/* a config instance */);
```
It is suggested to make the initialization as early as possible in your app. Please check `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config` for more configuration parameters. Once `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.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 `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence)` will throw an exception. You can use the `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback` class to be informed about the state of initialization. After initialization the `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#get()` function can be used to get the configured instance and the `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence)` function can be used to update a CharSequence with emoji EmojiSpans.

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

## Summary

| ### Nested types |
|---|
| `public abstract class https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config` Configuration class for EmojiCompat. |
| `public interface https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.GlyphChecker` Interface to check if a given emoji exists on the system. |
| `public abstract class https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback` Listener class for the initialization of the EmojiCompat. |
| `public interface https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.MetadataRepoLoader` Interface to load emoji metadata. |
| `public abstract class https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.MetadataRepoLoaderCallback` Callback to inform EmojiCompat about the state of the metadata load. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#EDITOR_INFO_METAVERSION_KEY() = "android.support.text.emoji.emojiCompat_metadataVersion"` Key in `https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#extras` that represents the emoji metadata version used by the widget. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#EDITOR_INFO_REPLACE_ALL_KEY() = "android.support.text.emoji.emojiCompat_replaceAll"` Key in `https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#extras` that represents `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setReplaceAll(boolean)` configuration parameter. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_DEFAULT() = 3` EmojiCompat instance is constructed, however the initialization did not start yet. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_FAILED() = 2` An unrecoverable error occurred during initialization of EmojiCompat. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_LOADING() = 0` EmojiCompat is initializing. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_SUCCEEDED() = 1` EmojiCompat successfully initialized. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STRATEGY_DEFAULT() = 0` `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` will start loading metadata when `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.EmojiCompat.Config)` is called. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STRATEGY_MANUAL() = 1` `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` will wait for `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#load()` to be called by developer in order to start loading metadata. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#REPLACE_STRATEGY_ALL() = 1` Replace strategy to add `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan`s for all emoji that were found. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#REPLACE_STRATEGY_DEFAULT() = 0` Replace strategy that uses the value given in `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config`. |
| `static final int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#REPLACE_STRATEGY_NON_EXISTENT() = 2` Replace strategy to add `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan`s only for emoji that do not exist in the system. |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#get()()` Return singleton EmojiCompat instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getAssetSignature()()` Returns signature for the currently loaded emoji assets. |
| `int` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()()` Returns loading state of the EmojiCompat instance. |
| `static boolean` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#handleDeleteSurroundingText(android.view.inputmethod.InputConnection,android.text.Editable,int,int,boolean)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/inputmethod/InputConnection.html inputConnection, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Editable.html editable, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int beforeLength, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int afterLength, boolean inCodePoints )` Handles deleteSurroundingText commands from `https://developer.android.com/reference/android/view/inputmethod/InputConnection.html` and tries to delete an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` from an `https://developer.android.com/reference/android/text/Editable.html`. |
| `static boolean` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#handleOnKeyDown(android.text.Editable,int,android.view.KeyEvent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Editable.html editable, int keyCode, https://developer.android.com/reference/android/view/KeyEvent.html event)` Handles onKeyDown commands from a `https://developer.android.com/reference/android/text/method/KeyListener.html` and if `keyCode` is one of `https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_DEL` or `https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_FORWARD_DEL` it tries to delete an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` from an `https://developer.android.com/reference/android/text/Editable.html`. |
| `boolean` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#hasEmojiGlyph(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html sequence)` Returns `true` if EmojiCompat is capable of rendering an emoji. |
| `boolean` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#hasEmojiGlyph(java.lang.CharSequence,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html sequence, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int metadataVersion )` Returns `true` if EmojiCompat is capable of rendering an emoji at the given metadata version. |
| `static https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.EmojiCompat.Config)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config config)` Initialize the singleton instance with a configuration. |
| `void` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#load()()` When `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setMetadataLoadStrategy(int)` is set to `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STRATEGY_MANUAL()`, this function starts loading the metadata. |
| `https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence)` Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. |
| `https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end )` Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. |
| `https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence,int,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxEmojiCount )` Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. |
| `https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence,int,int,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxEmojiCount, int replaceStrategy )` Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. |
| `void` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#registerInitCallback(androidx.emoji.text.EmojiCompat.InitCallback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback initCallback)` Registers an initialization callback. |
| `void` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#unregisterInitCallback(androidx.emoji.text.EmojiCompat.InitCallback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback initCallback)` Unregisters a callback that was added before. |

## Constants

### EDITOR_INFO_METAVERSION_KEY

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final String EDITOR_INFO_METAVERSION_KEY = "android.support.text.emoji.emojiCompat_metadataVersion"
```

Key in `https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#extras` that represents the emoji metadata version used by the widget. The existence of the value means that the widget is using EmojiCompat.
If exists, the value for the key is an `int` and can be used to query EmojiCompat to see whether the widget has the ability to display a certain emoji using `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#hasEmojiGlyph(java.lang.CharSequence,int)`.

### EDITOR_INFO_REPLACE_ALL_KEY

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final String EDITOR_INFO_REPLACE_ALL_KEY = "android.support.text.emoji.emojiCompat_replaceAll"
```

Key in `https://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#extras` that represents `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setReplaceAll(boolean)` configuration parameter. The key is added only if EmojiCompat is used by the widget. If exists, the value is a boolean.

### LOAD_STATE_DEFAULT

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int LOAD_STATE_DEFAULT = 3
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()` |   |

### LOAD_STATE_FAILED

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int LOAD_STATE_FAILED = 2
```

An unrecoverable error occurred during initialization of EmojiCompat. Calls to functions such as `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence)` will fail.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()` |   |

### LOAD_STATE_LOADING

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int LOAD_STATE_LOADING = 0
```

EmojiCompat is initializing.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()` |   |

### LOAD_STATE_SUCCEEDED

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int LOAD_STATE_SUCCEEDED = 1
```

EmojiCompat successfully initialized.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()` |   |

### LOAD_STRATEGY_DEFAULT

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int LOAD_STRATEGY_DEFAULT = 0
```

`https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` will start loading metadata when `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.EmojiCompat.Config)` is called.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setMetadataLoadStrategy(int)` |   |

### LOAD_STRATEGY_MANUAL

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int LOAD_STRATEGY_MANUAL = 1
```

`https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` will wait for `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#load()` to be called by developer in order to start loading metadata.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setMetadataLoadStrategy(int)` |   |

### REPLACE_STRATEGY_ALL

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int REPLACE_STRATEGY_ALL = 1
```

Replace strategy to add `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan`s for all emoji that were found.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence,int,int,int,int)` |   |

### REPLACE_STRATEGY_DEFAULT

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int REPLACE_STRATEGY_DEFAULT = 0
```

Replace strategy that uses the value given in `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence,int,int,int,int)` |   |

### REPLACE_STRATEGY_NON_EXISTENT

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static final int REPLACE_STRATEGY_NON_EXISTENT = 2
```

Replace strategy to add `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan`s only for emoji that do not exist in the system.

## Public methods

### get

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static EmojiCompat get()
```

Return singleton EmojiCompat instance. Should be called after `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.EmojiCompat.Config)` is called to initialize the singleton instance.

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat` | EmojiCompat instance |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if called before `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#init(androidx.emoji.text.EmojiCompat.Config)` |

### getAssetSignature

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public @NonNull String getAssetSignature()
```

Returns signature for the currently loaded emoji assets. The signature is a SHA that is constructed using emoji assets. Can be used to detect if currently loaded asset is different then previous executions. When used on devices running API 18 or below, returns empty string.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |

### getLoadState

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public int getLoadState()
```

Returns loading state of the EmojiCompat instance. When used on devices running API 18 or below always returns `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_SUCCEEDED()`.

| Returns |
|---|---|
| `int` | one of `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_DEFAULT()`, `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_LOADING()`, `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_SUCCEEDED()`, `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_FAILED()` |

### handleDeleteSurroundingText

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static boolean handleDeleteSurroundingText(
    @NonNull InputConnection inputConnection,
    @NonNull Editable editable,
    @IntRange(from = 0) int beforeLength,
    @IntRange(from = 0) int afterLength,
    boolean inCodePoints
)
```

Handles deleteSurroundingText commands from `https://developer.android.com/reference/android/view/inputmethod/InputConnection.html` and tries to delete an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` from an `https://developer.android.com/reference/android/text/Editable.html`. Returns `true` if an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` is deleted.
If there is a selection where selection start is not equal to selection end, does not delete. When used on devices running API 18 or below, always returns `false`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/inputmethod/InputConnection.html inputConnection` | InputConnection instance |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Editable.html editable` | TextView.Editable instance |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int beforeLength` | the number of characters before the cursor to be deleted |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int afterLength` | the number of characters after the cursor to be deleted |
| `boolean inCodePoints` | `true` if length parameters are in codepoints |

| Returns |
|---|---|
| `boolean` | `true` if an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` is deleted |

### handleOnKeyDown

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static boolean handleOnKeyDown(@NonNull Editable editable, int keyCode, KeyEvent event)
```

Handles onKeyDown commands from a `https://developer.android.com/reference/android/text/method/KeyListener.html` and if `keyCode` is one of `https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_DEL` or `https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_FORWARD_DEL` it tries to delete an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` from an `https://developer.android.com/reference/android/text/Editable.html`. Returns `true` if an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` is deleted with the characters it covers.
If there is a selection where selection start is not equal to selection end, does not delete. When used on devices running API 18 or below, always returns `false`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Editable.html editable` | Editable instance passed to `https://developer.android.com/reference/android/text/method/KeyListener.html#onKeyDown(android.view.View, android.text.Editable, int, android.view.KeyEvent)` |
| `int keyCode` | keyCode passed to `https://developer.android.com/reference/android/text/method/KeyListener.html#onKeyDown(android.view.View, android.text.Editable, int, android.view.KeyEvent)` |
| `https://developer.android.com/reference/android/view/KeyEvent.html event` | KeyEvent passed to `https://developer.android.com/reference/android/text/method/KeyListener.html#onKeyDown(android.view.View, android.text.Editable, int, android.view.KeyEvent)` |

| Returns |
|---|---|
| `boolean` | `true` if an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` is deleted |

### hasEmojiGlyph

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public boolean hasEmojiGlyph(@NonNull CharSequence sequence)
```

Returns `true` if EmojiCompat is capable of rendering an emoji. When used on devices running API 18 or below, always returns `false`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html sequence` | CharSequence representing the emoji |

| Returns |
|---|---|
| `boolean` | `true` if EmojiCompat can render given emoji, cannot be `null` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |

### hasEmojiGlyph

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public boolean hasEmojiGlyph(
    @NonNull CharSequence sequence,
    @IntRange(from = 0) int metadataVersion
)
```

Returns `true` if EmojiCompat is capable of rendering an emoji at the given metadata version. When used on devices running API 18 or below, always returns `false`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html sequence` | CharSequence representing the emoji |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int metadataVersion` | the metadata version to check against, should be greater than or equal to `0`, |

| Returns |
|---|---|
| `boolean` | `true` if EmojiCompat can render given emoji, cannot be `null` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |

### init

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public static EmojiCompat init(@NonNull EmojiCompat.Config config)
```

Initialize the singleton instance with a configuration. When used on devices running API 18 or below, the singleton instance is immediately moved into `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_SUCCEEDED()` state without loading any metadata. When called for the first time, the library will create the singleton instance and any call after that will not create a new instance and return immediately.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config` |   |

### load

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public void load()
```

When `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setMetadataLoadStrategy(int)` is set to `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STRATEGY_MANUAL()`, this function starts loading the metadata. Calling the function when `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setMetadataLoadStrategy(int)` is `not` set to `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STRATEGY_MANUAL()` will throw an exception. The load will `not` start if:

- the metadata is already loaded successfully and `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()` is `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_SUCCEEDED()`.
- a previous load attempt is not finished yet and `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#getLoadState()` is `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STATE_LOADING()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | when `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setMetadataLoadStrategy(int)` is not set to `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#LOAD_STRATEGY_MANUAL()` |

### process

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public CharSequence process(@NonNull CharSequence charSequence)
```

Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. When used on devices running API 18 or below, returns the given `charSequence` without processing it.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence` | CharSequence to add the EmojiSpans |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#process(java.lang.CharSequence,int,int)` |   |

### process

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public CharSequence process(
    @NonNull CharSequence charSequence,
    @IntRange(from = 0) int start,
    @IntRange(from = 0) int end
)
```

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

- If no emojis are found, `charSequence` given as the input is returned without any changes. i.e. charSequence is a String, and no emojis are found, the same String is returned.
- If the given input is not a Spannable (such as String), and at least one emoji is found a new `https://developer.android.com/reference/android/text/Spannable.html` instance is returned.
- If the given input is a Spannable, the same instance is returned.

When used on devices running API 18 or below, returns the given `charSequence` without processing it.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence` | CharSequence to add the EmojiSpans, cannot be `null` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start` | start index in the charSequence to look for emojis, should be greater than or equal to `0`, also less than or equal to `charSequence.length()` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end` | end index in the charSequence to look for emojis, should be greater than or equal to `start` parameter, also less than or equal to `charSequence.length()` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | in the following cases: `start < 0`, `end < 0`, `end < start`, `start > charSequence.length()`, `end > charSequence.length()` |

### process

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public CharSequence process(
    @NonNull CharSequence charSequence,
    @IntRange(from = 0) int start,
    @IntRange(from = 0) int end,
    @IntRange(from = 0) int maxEmojiCount
)
```

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

- If no emojis are found, `charSequence` given as the input is returned without any changes. i.e. charSequence is a String, and no emojis are found, the same String is returned.
- If the given input is not a Spannable (such as String), and at least one emoji is found a new `https://developer.android.com/reference/android/text/Spannable.html` instance is returned.
- If the given input is a Spannable, the same instance is returned.

When used on devices running API 18 or below, returns the given `charSequence` without processing it.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence` | CharSequence to add the EmojiSpans, cannot be `null` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start` | start index in the charSequence to look for emojis, should be greater than or equal to `0`, also less than or equal to `charSequence.length()` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end` | end index in the charSequence to look for emojis, should be greater than or equal to `start` parameter, also less than or equal to `charSequence.length()` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxEmojiCount` | maximum number of emojis in the `charSequence`, should be greater than or equal to `0` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | in the following cases: `start < 0`, `end < 0`, `end < start`, `start > charSequence.length()`, `end > charSequence.length()``maxEmojiCount < 0` |

### process

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public CharSequence process(
    @NonNull CharSequence charSequence,
    @IntRange(from = 0) int start,
    @IntRange(from = 0) int end,
    @IntRange(from = 0) int maxEmojiCount,
    int replaceStrategy
)
```

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

- If no emojis are found, `charSequence` given as the input is returned without any changes. i.e. charSequence is a String, and no emojis are found, the same String is returned.
- If the given input is not a Spannable (such as String), and at least one emoji is found a new `https://developer.android.com/reference/android/text/Spannable.html` instance is returned.
- If the given input is a Spannable, the same instance is returned.

When used on devices running API 18 or below, returns the given `charSequence` without processing it.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence` | CharSequence to add the EmojiSpans, cannot be `null` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start` | start index in the charSequence to look for emojis, should be greater than or equal to `0`, also less than or equal to `charSequence.length()` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end` | end index in the charSequence to look for emojis, should be greater than or equal to `start` parameter, also less than or equal to `charSequence.length()` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxEmojiCount` | maximum number of emojis in the `charSequence`, should be greater than or equal to `0` |
| `int replaceStrategy` | whether to replace all emoji with `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan`s, should be one of `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#REPLACE_STRATEGY_DEFAULT()`, `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#REPLACE_STRATEGY_NON_EXISTENT()`, `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#REPLACE_STRATEGY_ALL()` |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if not initialized yet |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | in the following cases: `start < 0`, `end < 0`, `end < start`, `start > charSequence.length()`, `end > charSequence.length()``maxEmojiCount < 0` |

### registerInitCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public void registerInitCallback(@NonNull EmojiCompat.InitCallback initCallback)
```

Registers an initialization callback. If the initialization is already completed by the time the listener is added, the callback functions are called immediately. Callbacks are called on the main looper.
When used on devices running API 18 or below, `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback#onInitialized()` is called without loading any metadata. In such cases `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback#onFailed(java.lang.Throwable)` is never called.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback initCallback` | the initialization callback to register, cannot be `null` |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat#unregisterInitCallback(androidx.emoji.text.EmojiCompat.InitCallback)` |   |

### unregisterInitCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.0.0)

```
public void unregisterInitCallback(@NonNull EmojiCompat.InitCallback initCallback)
```

Unregisters a callback that was added before.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.InitCallback initCallback` | the callback to be removed, cannot be `null` |