Search code examples
androidemoticons

Encoding and decoding emoji for cross plateforms


I am currently working on an android instant messaging application .It is working fine .I am successful in sending messages from one mobile to another,from mobile to web application.i am using library compile 'com.rockerhieu.emojicon:library:1.3.3' to handle emoticons . Using this library , i am adding a panel of emoticons .It is working fine for sending emoticon from one mobile to another .But web application is not getting the emoticon which i am sending .

ScreenShot

Enoji

As u can see in the screen shot a different symbol is displayed in the web application .

Screen Shot of mobile app

Mobile App Screen Shot

Here is the main problem,i am not getting in web app what i am sending through my mobile App.

ChatActivity.java

     public class ChatActivity extends FragmentActivity implements
        EmojiconGridFragment.OnEmojiconClickedListener, EmojiconsFragment.OnEmojiconBackspaceClickedListener {

    EmojiconEditText edMessage = (EmojiconEditText) findViewById(R.id.edtMessage);
 @Override
    public void onEmojiconBackspaceClicked(View view) {
        EmojiconsFragment.backspace(edMessage);
    }

    @Override
    public void onEmojiconClicked(Emojicon emojicon) {
        EmojiconsFragment.input(edMessage, emojicon);
    }

}

Please help me to fix the issue.


Solution

  • By using edMessage.getText().toString().trim() you can get string

    Converting String to Unicode

        public static String unicodeEscaped(char ch) {
                if (ch < 0x10) {
                    return "\\u000" + Integer.toHexString(ch);
                } else if (ch < 0x100) {
                    return "\\u00" + Integer.toHexString(ch);
                } else if (ch < 0x1000) {
                    return "\\u0" + Integer.toHexString(ch);
                }
                return "\\u" + Integer.toHexString(ch);
            }
    
            String unicode = "";
           String text = _msgEditText.getText().toString().trim();
           for (int i = 0; i < text.length(); i++) {
           unicode = unicode+Constant.unicodeEscaped(text.charAt(i));
                                }
    text = unicode;
    

    And for decoding it you can use common-lang.jar file.
    Please refer link Click here

    _msgString = StringEscapeUtils.unescapeJava(_msgString); // for decoding unicode to string or for similar language