Ok. I figured out how to get it to work. Per user6526330's link. I first had to add the library commons-lang-2.5.jar and use the following for the EditText and 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);
That wasn't enough to get things to work though because the standard EditText and TextView doesn't know how to translate the emoji code. So I found the library Emojicon here.
Using the TextView and EditText from that library allowed me to post and receive the text with embedded emoji properly.
I also had to change my database charset to utf8md4_unicode_ci for my database to see it properly.
Because I was using PDO to post the comment, I had to change this line:
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
to
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8mb4", $username, $password, $options);
So for anyone else that may see this and want to have emoji support in their app, here is the checklist you would need to follow:
- Make sure your database collation/charset is utf8mb4 by following this link.
- Add the commons-lang-2.5 library to your project from here.
- Add the Emojicon library to your project from here.
- Add the TextView and EditText view from the library to their respective layouts.
- Follow the code posted above to convert your emoji text into utf8mb4 encoding.
- Enjoy!
Hope this helps someone else. Thank you everyone for your help.