3

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?

gus27
  • 2,616
  • 1
  • 21
  • 25
M.Hadi
  • 41
  • 5

1 Answers1

5

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));
gus27
  • 2,616
  • 1
  • 21
  • 25