Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send text with emoji to server. #1

Closed
vgevorgyan opened this issue Feb 25, 2014 · 15 comments
Closed

Send text with emoji to server. #1

vgevorgyan opened this issue Feb 25, 2014 · 15 comments
Assignees
Labels

Comments

@vgevorgyan
Copy link

Hello,

I have problem with send the text with emoji to server.
When I send they are becoming to ???.
Server side work perfectly, because I have tested it with the iOS version.

Any suggestion?

Thanks,
Vardan

@rockerhieu
Copy link
Owner

What's the encoding you're using when sending text with emoji to server from Android? Can you try with sending other unicode text e.g: Xin Chào Các Bạn to see if you will see it correctly on the server?

@rockerhieu rockerhieu self-assigned this Feb 27, 2014
@rockerhieu
Copy link
Owner

Ok, let's close this issue. This should be an issue outside of the library.

@4tis
Copy link

4tis commented Mar 17, 2014

Hi there,

I would like to know what is the encoding I should use at the SQL row of the text in order to pass the icons right and not getting a gibberish result :)

Thanks for any kind of help

@vgevorgyan
Copy link
Author

Hi,

I'm using utf8mb4_unicode_ci for table and utf8mb4_general_ci for column.

rockerhieu: I still have the same issue. I'm using UTF8 and yes other unicode characters working well.

@4tis
Copy link

4tis commented Mar 17, 2014

Well thank you for the reply,

I've tried the next code for the table -

CREATE TABLE IF NOT EXISTS `messages` (

id int(255) NOT NULL AUTO_INCREMENT,
fromuid int(255) NOT NULL,
touid int(255) NOT NULL,
sentdt datetime NOT NULL,
read tinyint(1) NOT NULL DEFAULT '0',
readdt datetime DEFAULT NULL,
messagetext longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
messagetext1 longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (id),
KEY id (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=22 ;

And i've also added to the index.php - the next line -

header('Content-type: text/html; charset=utf-8');

But with it or without it - i still don't get to pass the icons right.

CAn you tell what I'm doing wrong here?

@vgevorgyan
Copy link
Author

Check this http://mathiasbynens.be/notes/mysql-utf8mb4

Luckily, MySQL 5.5.3 (released in early 2010) introduced a new encoding called utf8mb4 which maps to proper UTF-8 and thus fully supports Unicode, including astral symbols.

@vgevorgyan
Copy link
Author

After run that code did you checked is table has utf8mb4 character set?

@4tis
Copy link

4tis commented Mar 17, 2014

It says the table got - utf8mb4_unicode_ci and also messagetext and messagetext1 got - messagetext.

The thing is, When I'm looking at the Collation options at the myPhpAdmin - i don't have utf8mb4 option at all

@farruxx
Copy link

farruxx commented Jun 22, 2014

hi there, i have the same problem. the symbols saving as "??????????" when i using utf8mb4

@qadir227
Copy link

qadir227 commented Dec 5, 2014

Any solution?

@farruxx
Copy link

farruxx commented Dec 5, 2014

We are using blob field

@qadir227
Copy link

qadir227 commented Dec 5, 2014

@farruxx thanks for reply.
but I can't use the blob field. Its like a facebook app. user can update status i.e they can send text and emoji in the field. I have to save both text in the same field.

@farruxx
Copy link

farruxx commented Dec 5, 2014

The problem is at saving data without changing. Blob will save data as is

@qadir227
Copy link

qadir227 commented Dec 8, 2014

I have solved the issue. Here is the code Which I have used to send the text+emojis to server

String enCodedStatusCode = "";

            try {
                enCodedStatusCode = URLEncoder.encode(statusText,
                        HTTP.UTF_8);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

and to display this text to textview from server I have used this code

String myString= null;
try {
myString= URLDecoder.decode(
mUserWallData.getPost_status(), "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

            //System.out.println(myString);

            txtPostText.setText(myString);

simply used the URLEncoder.encode to UTF-8 (Sending to server) and then URLDecoder.decode from UTF-8 (Received text from server)

rockerhieu pushed a commit that referenced this issue Dec 4, 2015
@MustanserIqbal93
Copy link

I got the solution for saving Emoji in Database
do it like this in android code

Encoding:

byte[] data = editTextFieldWithEmojis.getText().toString().getBytes("UTF-8"); base64String = Base64.encodeToString(data, Base64.DEFAULT);

Decofing

byte[] data = Base64.decode(stringWithEmojis, Base64.DEFAULT); newStringWithEmojis = new String(data, "UTF-8");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants