Reputation: 863
I need to handle smileys in one of my android project. I did it by doing utfencoding when I am sending post request and doing decoding when I receive response. The problem is arising with mysql character limit as while inserting its saving encoded response and sending same back to android device. so in android a smiley is counted as one character and on mysql its around 4-5 characters per smiley. I know the possible solution could be saving decoded sring in mysql but then most of the time its corrupting the emojis when decoding when saving to server and encoding the string while sending the response. I had used following functions for encoding and decoding the request and response respectively
val = URLEncoder.encode(string, "UTF-8");
value = URLDecoder.decode(text, "UTF-8");
Upvotes: 2
Views: 566
Reputation: 156
No need to handle these things in server..we, the android developers can handle these things like follow..
EditText etEmojiEditText;
Now get the entered emoji in the form of string..
String toServer = etEmojiEditText.getText();
String toServerUnicodeEncoded = StringEscapeUtils.escapeJava(toServer);
Decoding for above encoding as follows..
String serverResponse = toServerUnicodeEncoded;
String fromServerUnicodeDecoded =StringEscapeUtils.unescapeJava(serverResponse);
Upvotes: 0
Reputation: 387
check the link, already has answered:
How to store Emoji Character in My SQL Database
It must be controlled from the server side & database to store character correctly.
Upvotes: 0
Reputation: 134
The unicodes for emoticons are fully supported by the UTF-8 encoding, but MySQL’s utf8 does not! To save emoticons to a MySQL database you need to use utf8mb4. The difference between MySQL’s utf8
and utf8mb4
is that the former can only store 3 byte characters whereas the latter can store 4 byte ones.
Example for setting database collation:
SET NAMES utf8mb4;
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
Upvotes: 1