# EmojiCompat.GlyphChecker

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.GlyphChecker) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/emoji#1.2.0)

*** ** * ** ***


```
public interface EmojiCompat.GlyphChecker
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `abstract boolean` | `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.GlyphChecker#hasGlyph(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 sdkAdded )` Return `true` if the emoji that is in `charSequence` between `start`(inclusive) and `end`(exclusive) can be rendered on the system using the default Typeface. |

## Public methods

### hasGlyph

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

```
abstract boolean hasGlyph(
    @NonNull CharSequence charSequence,
    @IntRange(from = 0) int start,
    @IntRange(from = 0) int end,
    @IntRange(from = 0) int sdkAdded
)
```

Return `true` if the emoji that is in `charSequence` between `start`(inclusive) and `end`(exclusive) can be rendered on the system using the default Typeface.

This function is called after an emoji is identified in the given `charSequence` and EmojiCompat wants to know if that emoji can be rendered on the system. The result of this call will be cached and the same emoji sequence won't be asked for the same EmojiCompat instance.

When the function returns `true`, it will mean that the system can render the emoji. In that case if `https://developer.android.com/reference/androidx/emoji/text/EmojiCompat.Config#setReplaceAll(boolean)` is set to `false`, then no `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` will be added in the final emoji processing result.

When the function returns `false`, it will mean that the system cannot render the given emoji, therefore an `https://developer.android.com/reference/androidx/emoji/text/EmojiSpan` will be added to the final emoji processing result.

The default implementation of this class uses `https://developer.android.com/reference/androidx/core/graphics/PaintCompat#hasGlyph(android.graphics.Paint,java.lang.String)` function to check if the emoji can be rendered on the system. This is required even if EmojiCompat knows about the SDK Version that the emoji was added on AOSP. Just the `sdkAdded` information is not enough to reliably decide if emoji can be rendered since this information may not be consistent across all the OEMs and all the Android versions.
With this interface you can apply your own heuristics to check if the emoji can be rendered on the system. For example, if you'd like to rely on the `sdkAdded`information, and some predefined OEMs, it is possible to write the following code snippet.

```java
static class MyGlyphChecker implements EmojiCompat.GlyphChecker {
    private TextPaint mTextPaint = new TextPaint();

    @Override
    public boolean hasGlyph(@NonNull CharSequence charSequence, int start, int end,
            int sdkAdded) {
        if (isOnDeviceX()) {
            // if on this specific device we only rely on sdkAdded
            return sdkAdded < Build.VERSION.SDK_INT;
        } else {
            String string = createString(charSequence, start, end);
            return PaintCompat.hasGlyph(mTextPaint, string);
        }
    }

}
```

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html charSequence` | the CharSequence that is being processed |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int start` | the inclusive starting offset for the emoji in the `charSequence` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int end` | the exclusive end offset for the emoji in the `charSequence` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int sdkAdded` | the API version that the emoji was added in AOSP |

| Returns |
|---|---|
| `boolean` | true if the given sequence can be rendered as a single glyph, otherwise false. |