is String Contains Emoji - Android Graphics

Android examples for Graphics:Spannable

Description

is String Contains Emoji

Demo Code


//package com.java2s;
import android.text.TextUtils;

public class Main {

    public static boolean isContainsEmoji(String source) {
        if (isEmpty(source)) {
            return false;
        }/*from ww  w  .java 2s .  com*/
        int len = source.length();
        for (int i = 0; i < len; i++) {
            char codePoint = source.charAt(i);
            if (isEmojiCharacter(codePoint)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isEmpty(CharSequence chars) {
        return TextUtils.isEmpty(chars);
    }

    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