Is a string contains Emoji character - Android java.lang

Android examples for java.lang:String Unicode

Description

Is a string contains Emoji character

Demo Code

import android.text.TextUtils;
import java.util.regex.Pattern;

public class Main{

    public static boolean containsEmoji(String source) {
        int len = source.length();
        for (int i = 0; i < len; i++) {
            char codePoint = source.charAt(i);
            if (!isEmojiCharacter(codePoint)) { 
                return true;
            }/*from  w w  w .  j  a va 2 s. com*/
        }
        return false;
    }
    private static boolean isEmojiCharacter(char codePoint) {
        return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) ||
                (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
                ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000)
                && (codePoint <= 0x10FFFF));
    }
}

Related Tutorials