Android Disable Emoji in Edittext

If you have same requirement in development, this article may help you.

Let’s how to do it in code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static InputFilter EMOJI_FILTER = new InputFilter() {

@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for (int index = start; index < end; index++) {

int type = Character.getType(source.charAt(index));

if (type == Character.SURROGATE) {
return "";
}
}
return null;
}
};

And you also need to set this filter in the edittext you want to disable Emoji.

1
editText.setFilters(new InputFilter[]{EMOJI_FILTER});

Why it can disable Emoji.

Unicode is a computing industry standard for the consistent encoding, representation, and handling of text expressed in most of the world’s writing systems.

Emoji use area of Unicode with a range of code points from U+1F604 to U+1F539.
And Character.SURROGATEreserved the range is over the Emoji’s.

If you find a better method, you also can contact with me