直接上代码了,用于判断字符串中是否有表情
1 public class EmojiUtils { 2 /** * 检测是否有emoji表情 * @param source * @return */ 3 public static boolean containsEmoji(String source) { 4 int len = source.length(); 5 for (int i = 0; i < len; i++) { 6 char codePoint = source.charAt(i); 7 if (!isEmojiCharacter(codePoint)) { //如果不能匹配,则该字符是Emoji表情 8 return true; 9 } 10 } 11 return false; 12 } 13 14 15 /** * 判断是否是Emoji * @param codePoint 比较的单个字符 * @return */ 16 private static boolean isEmojiCharacter(char codePoint) { 17 return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) 18 || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) 19 || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) 20 || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF)); 21 } 22 }
直接使用就ok了,哈哈哈哈哈哈哈