Android Question Emoji storage and UTF8

AndOrNot

Well-Known Member
Licensed User
Hi all, i have a little server hosted in altervista .org. Mysql db of altervista doesn't support utf32 , or utfmb4, so when i try to insert an emoji on editbox my app can see it, but when i store the message in db online it will store "????". So i think the i can replace emoji from my edit box with a spefic value, for example hex value of emoji or unicode.

I can write emoji using its codeint (e.g 1f600) with the following code:
B4X:
Dim bc As ByteConverter
Dim b() As Byte = bc.IntsToBytes(Array As Int(0x1F600))
Msgbox(BytesToString(b, 0, 4, "UTF32"),"")

But i am not able to get the code from the emoji wrote in edittext, before send it in db. Can anyone help me? I tried the following code, but it doesn't works

B4X:
  Dim b() As Byte = bc.StringToBytes(text,"UTF32")
  Dim c() As Int = bc.IntsFromBytes(b)
  Msgbox(c(0),0x1F600)
 

AndOrNot

Well-Known Member
Licensed User
Why do you convert it to an array of ints? Why not store it as a blob (array of bytes)?
I have an entire text, and maybe in this text there are emoticon. Should I convert all text as blob and store in db blob like text?
 
Upvote 0

AndOrNot

Well-Known Member
Licensed User
I solved it using the following code

Put:
B4X:
Dim text2 As StringUtils
Dim b() As Byte = text2.DecodeBase64(m.Get("Colum"))
lbl2.Text = BytesToString(b,0,b.Length,"UTF-8")

Read:
B4X:
Dim su As StringUtils
Dim query As String = "INSERT INTO Commenti (Colum) VALUES ('"&su.EncodeBase64(txtComm.Text.GetBytes("UTF8")&"')
 
Upvote 0

Similar Threads

Top