how to encode and decode emoji in android? -
I use the library in my application when I pass a static unicode string in my code then the emoji is visible, But if I send emoji to the php server using a similar service and withdraw the string then it is showing the Unicode string in my application. If I compare, then both the static and the server recovered strings are the same.
Can anyone tell me what I did wrong in my application? The same application has been developed in iOS and what they have done for the first time they send the string to ASCII> UTF-8 on the server while encoding. Then they are decoding the string as they send it. Can someone suggest me if it will be compatible with Android, if so, how can I do this?
We use Commons-Lang (Commons-Lang-2.5.jar) for the encoding and decoding of Unicode characters. You can use the library. Download jar file or use gradle: compile 'org.apache.commons: commons-lang3: 3.4'
.
For encoding use - StringEscapeUtils.escapeJava (string text)
this Android EditText
call getText < / Code> method, where it will properly encode the Unicode characters before sending it to the web server.
For decoding use - StringEscapeUtils.unescapeJava (string text)
Use it in Android TextView
in the settext < / Code>, where it will interpret unicode characters properly after receiving a response from the web server.
Ex:
Edit Text EEmojiEditText = new edit text (this); EtEmojiEditText.setText ("Write something in EMOJI"); String Tusher = etEmojiEditText.getText (); String Tusher Yuododangode = String Xscape Youthil Escapjava (towersaver); String Server Response = "Some Answers to Servers from Unicode Characters"; ServerUnicodeDecoded from String = StringEscapeUtils.unescapeJava (serverResponse);
FYI Also use encoding and decoding for the web service side. Unicode encoded string must be decoded from the web service and the web service The response from should be encoded. In the server tables, utf8mb4 should be utf8 instead, because the Unicode character requires 4bytes per character, so the Unoded will not be displayed in 3bytes.
Comments
Post a Comment