I try to get the emoji code inside a long string from database, in this format: 0x1F60A ... So I can access the code but it will be a String.
At first, I tried to cast the variable by doing tv.setText(beforeEmo + getEmijoByUnicode((int)emoKind)); but Android Studio hints: "cannot cast 'java.lang.String' to int"...
The getEmijoByUnicode method is:
public String getEmijoByUnicode(int unicode) {
return new String(Character.toChars(unicode));
}
So I tried this one:
tv.setText(beforeEmo + getEmijoByUnicode(Integer.parseInt(emoKind)));
but it crashes with NumberFormatError. Is there any way to make the emoji appear in my text?
Try
Integer.parseInt("1F60A", 16);
or
Long.parseLong("1F60A", 16);
to convert the string to int or long. So you have to get rid of the "0x", like this
getEmijoByUnicode(Integer.parseInt(emoKind.substring(2), 16));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With