且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在MySQL中存储Android表情符号

更新时间:2022-12-11 14:10:55

要将表情符号存储到Mysql数据库中,请将要存储的字符串转换为编码的Base 64字符串.在您的应用程序方面,您所要做的就是使用Base 64对该字符串进行解码.

To store emojis into a Mysql Database convert the string you are storing into an encoded Base 64 string. On your application side all you have to do is decode that string using Base 64.

编码

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

解码

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