Deepak Goyal
1 min readNov 28, 2018

--

Hi Dhamodharan,

Let me explain this

You can get the data from edit text by using

editText.getText().toString();

But if the edit text has emojis then it will give you the data like below

Hey 💃🏻

And you cannot save the above text directly in the database. So you have to get the emojis as Unicode. To get the emoji Unicode you have to escape the emoji text. Add the following apache library in your project

implementation 'org.apache.commons:commons-text:1.6'

Then import the following in your activity or Fragment

import org.apache.commons.text.StringEscapeUtils

Usage:

String text = editText.getText().toString();
String escapeText = StringEscapeUtils.escapeJava(text);
// this will give you the emojis as the unicode
// Hey \uD83D\uDC83\uD83C\uDFFB

Now you can save the `escapeText` anywhere you want. And to convert back the escaped text to emoji, you can use

String unescapedText = StringEscapeUtils.unescapeJava(escapeText);
// this will convert the unicode to emojis
// Hey 💃🏻

Let me know if you need further any help.

Thanks.

--

--

Deepak Goyal
Deepak Goyal

Written by Deepak Goyal

I’m a Software Engineer. I love programming. #java #android #kotlin #dart #flutter #firebase

Responses (1)