Android Question is there a good solution for Display EMOJI in

Ju Yang

Active Member
Licensed User
Longtime User
ASP.NET(Web),B4A,B4i and B4J?


We are making a CRM with chat module using B4X, and have ASP.NET(Web),B4A,B4i and B4J platform,

How to make a good solution for Display EMOJI in all those platforms?

help! thank all guys very much! ~_~
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This forum is not for ASP.Net questions.

Emojis are Unicode characters. You can use UTF32 to create such characters:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   EditText1.Text = UTS(0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
End Sub


Sub UTS (codepoint As Int) As String
  Dim bc As ByteConverter
  Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
  Return BytesToString(b, 0, 4, "UTF32")
End Sub
You need to add a reference to ByteConverter library in B4A and B4J, and iRandomAccessFile in B4i.

It will work in B4A, B4J and B4i:
SS-2015-12-06_08.55.22.png

SS-2015-12-06_08.55.59.png

SS-2015-12-06_08.56.24.png



B4J

The desktop font doesn't support emojis. So you need to include a custom font, such as: https://github.com/MorbZ/OpenSansEmoji
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.Show
   MainForm.RootPane.LoadLayout("1")
   fx.LoadFont(File.DirAssets, "OpenSansEmoji.ttf", 32)
   Label1.Style = Label1.Style & "-fx-font-family: OpenSansEmoji;"
   Label1.Text = UTS(0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
   TextField1.Style = TextField1.Style & "-fx-font-family: OpenSansEmoji;"
   TextField1.Text = UTS(0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
End Sub

Sub UTS (codepoint As Int) As String
  Dim bc As ByteConverter
  Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
  Return BytesToString(b, 0, 4, "UTF32")
End Sub
 
Upvote 0

Ju Yang

Active Member
Licensed User
Longtime User
But we need all platforms' EMOJI image is same, like iOS EMOJI. how to implement?
 
Upvote 0

Kwame Twum

Active Member
Licensed User
Longtime User
I tried naming my emojis like below.
emoj.png

then I tried parsing the filename to an Int (without the extension) using the sub below:
B4X:
Sub emo_Click(Thumbnail As Panel)
    Dim coda As String = Thumbnail.Tag
    coda = c.GetFileName(coda).Replace(".png","")
    coda = "0x" & coda : Log(coda)            'This prints 0x1F601 to the logs for the first emoji
    Dim code As Int = Bit.ParseInt(coda,16)
    txt.Text = txt.Text & UTS(code)            'I get java.lang.NumberFormatException: Invalid int: "0x1F601" on this line
End Sub

What could I be doing wrong?
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I tried naming my emojis like below.
View attachment 42177
then I tried parsing the filename to an Int (without the extension) using the sub below:
B4X:
Sub emo_Click(Thumbnail As Panel)
    Dim coda As String = Thumbnail.Tag
    coda = c.GetFileName(coda).Replace(".png","")
    coda = "0x" & coda : Log(coda)            'This prints 0x1F601 to the logs for the first emoji
    Dim code As Int = Bit.ParseInt(coda,16)
    txt.Text = txt.Text & UTS(code)            'I get java.lang.NumberFormatException: Invalid int: "0x1F601" on this line
End Sub

What could I be doing wrong?
Can I ask how do you replace the default characters with those images?
 
Upvote 0

Leni Berry

Active Member
Licensed User
Longtime User
How to convert this output
This forum is not for ASP.Net questions.

Emojis are Unicode characters. You can use UTF32 to create such characters:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   EditText1.Text = UTS(0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
End Sub


Sub UTS (codepoint As Int) As String
  Dim bc As ByteConverter
  Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
  Return BytesToString(b, 0, 4, "UTF32")
End Sub
You need to add a reference to ByteConverter library in B4A and B4J, and iRandomAccessFile in B4i.

It will work in B4A, B4J and B4i:
SS-2015-12-06_08.55.22.png

SS-2015-12-06_08.55.59.png

SS-2015-12-06_08.56.24.png



B4J

The desktop font doesn't support emojis. So you need to include a custom font, such as: https://github.com/MorbZ/OpenSansEmoji
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.SetFormStyle("UNIFIED")
   MainForm.Show
   MainForm.RootPane.LoadLayout("1")
   fx.LoadFont(File.DirAssets, "OpenSansEmoji.ttf", 32)
   Label1.Style = Label1.Style & "-fx-font-family: OpenSansEmoji;"
   Label1.Text = UTS(0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
   TextField1.Style = TextField1.Style & "-fx-font-family: OpenSansEmoji;"
   TextField1.Text = UTS(0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
End Sub

Sub UTS (codepoint As Int) As String
  Dim bc As ByteConverter
  Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
  Return BytesToString(b, 0, 4, "UTF32")
End Sub

Yes, i can display emoji icon from this UTS function into textboxt. but how to translate this emoji into string that can be save to database?
 
Upvote 0

Leni Berry

Active Member
Licensed User
Longtime User
How to convert this output


Yes, i can display emoji icon from this UTS function into textboxt. but how to translate this emoji into string that can be save to database?
my mistake... database show me '????' because i set this charset for the connection database.

mysqli_set_charset($connection,"utf8");

just remove this charset. everything back to normal...
 
Upvote 0
Top