Android过滤emoji表情

来源:互联网 发布:linux命令大全解析 编辑:程序博客网 时间:2024/05/10 06:15
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 ) ;              //Gionee <zhangjinbiao> <2016-12-26> modify for <50238> end                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

android java unicode 之间的关系 



0 0