Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]|" +
"[\ud83e\udd00-\ud83e\uddff]|[\u2300-\u23ff]|[\u2500-\u25ff]|[\u2100-\u21ff]|[\u0000-\u00ff]|[\u2b00-\u2bff]|[\u2d06]|[\u3030]"
,Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE ) ;
Matcher matcher = emoji.matcher(song);
Matcher matcher2 = emoji.matcher(songer);
if(matcher.find()||matcher2.find()){
Toast.makeText(mActivity, R.string.bell_diy_save_illegal_name, 0).show();
}else{
//Gionee <zhangjinbiao> <2016-12-26> modify for <50238> begin
// String strUtf_16 = new String(songer.getBytes());
//byte[] bytes = strUtf_16.getBytes(StandardCharsets.UTF_16);
//char[] charArr = strUtf_16.toCharArray();
byte[] bytes = songer.getBytes(StandardCharsets.UTF_16);
for(byte c : bytes){
Log.e("Emoji", Integer.toHexString((int)c) + " byte value: " + c);
}
上述的正则表达式是的编码是utf-16的编码。
在线编码转换http://www.qqxiuzi.cn/bianma/Unicode-UTF.php
可参考博客
Android 准确过滤(禁止) Emoji表情
http://apps.timwhitlock.info/emoji