好的。我想出了如何让它工作。每个用户 6526330 的链接。我首先必须添加库 commons-lang-2.5.jar 并将以下内容用于 EditText 和 TextView。
//This converted the emoji code to utf8md4 for the server
String cmttxt = newCmnt.getText().toString().trim();
String toServerUnicodeEncoded = StringEscapeUtils.escapeJava(cmttxt);
//This converted the server response to properly show the emoji
String serverResponse = "Some string from server with emoji code embedded";
String fromServerUnicodeDecoded = StringEscapeUtils.unescapeJava(serverResponse);
这还不足以让事情正常进行,因为标准的 EditText 和 TextView 不知道如何翻译表情符号代码。于是我找到了库 Emojicon here。
使用该库中的 TextView 和 EditText 允许我正确发布和接收带有嵌入表情符号的文本。
我还必须将我的数据库字符集更改为 utf8md4_unicode_ci 才能让我的数据库正确查看。
因为我是使用 PDO 发布评论,所以我不得不更改这一行:
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
到
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8mb4", $username, $password, $options);
因此,对于可能看到此内容并希望在其应用中支持表情符号的任何其他人,您需要遵循以下清单:
- 通过this 链接确保您的数据库排序规则/字符集为 utf8mb4。
- 将 commons-lang-2.5 库从 here 添加到您的项目。
- 将 Emojicon 库从 here 添加到您的项目。
- 将库中的 TextView 和 EditText 视图添加到各自的布局中。
- 按照上面发布的代码将您的表情符号文本转换为 utf8mb4 编码。
- 享受吧!
希望这对其他人有所帮助。谢谢大家的帮助。