I'm trying to use emoji in my EditText
Fields. But the problem is that when I try to convert emoji into hexa the value is not correct.
I'm using this function to get emoji value in Hexa.
public static String escapeJavaString(String st){
StringBuilder builder = new StringBuilder();
try {
for (int i = 0; i < st.length(); i++) {
char c = st.charAt(i);
if(!Character.isLetterOrDigit(c) && !Character.isSpaceChar(c)&& !Character.isWhitespace(c) ){
String hexa= String.valueOf(c);
int code = (int)c;
if(!(code >= 0 && code <= 255)){
hexa= "0x"+Integer.toHexString(c);
}
builder.append(unicode);
}
else{
builder.append(c);
}
}
Log.i(TAG, builder.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return builder.toString();
}
I tried to add smiley face and it give me value 0xd83d
Which is not work in below function.
And Here is function to convert Hexa value into Emoji, This function is working fine I tried it with providing manual Hexa value.
// 0xd83d this value is get from above function but not work
// in this function
//String hexaCode = "0xd83d"; // not work
String hexaCode = "0x1F60A"; // work
int emoji= Integer.parseInt(hexaCode.substring(2), 16);
reurn new String(Character.toChars(emoji));
Can you please let me know what am I doing wrong. Please don't refer me to any emoji library.