2

I have developed android keyboard and I want to add emoji to it for example the code to view 'k' is

<Key android:codes="107" android:keyLabel="k"/>

107 is the ascii code for 'k' letter you can find all ascii from this website http://www.addressmunger.com/special_ascii_characters/

if you searched for 'k' you will get &#107; and my problem is if I want to put this emoji for example the ascii I got is &#55357;&#56850; I don't know how to put this ascii in the xml .. any help?

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74

1 Answers1

2

You should find this WILL NOT work:

<Key android:codes="0x1F602" android:keyLabel="0x1F602"/>

Instead in the .xml layout file, for each emoji you want to add, create a line like this:

    <!--'Face with tears of joy' -->
<Key android:codes="0x1F602" android:keyLabel="\ud83d\ude02"/>

The "\ud83d\ude02" is called a Java Escape sequence (16 bit).

If your using the standard SoftKeyboard (or some derivative), you will have to change it to handle the escape characters. You should have a class called SoftKeyboard which extends InputMethodService. Inside there should be a method called handleCharacter. Change this line:

getCurrentInputConnection().commitText(String.valueOf((char) primaryCode), 0);

To this line:

getCurrentInputConnection().commitText(String.valueOf(Character.toChars(primaryCode)), 1);

Code Referenced from : display built-in emoji keys for inputmethod

Other References:
http://android.appstorm.net/how-to/customization/how-to-use-emojis-on-your-android-device/

Emoji Keyboard support for EditField in android

set font at runtime, Textview

Jon Goodwin
  • 9,053
  • 5
  • 35
  • 54
  • thank you for reply.. the emoji appear in the keyboard but it didnt write anything .. kindly see the picture http://www8.0zz0.com/2017/08/09/15/386601306.png – khalid bitar Aug 09 '17 at 12:19
  • Which font are you using for your Textview/Edittext ? AndroidEmoji.ttf and NotoColorEmoji.ttf is a good ones I think. – Jon Goodwin Aug 09 '17 at 14:15
  • EmojiconEditText is probably what you need:- https://www.androidhive.info/2016/11/android-integrate-emojis-keyboard-app/ – Jon Goodwin Aug 09 '17 at 14:36
  • Android's default font (Roboto, as on 4.0+) includes only monochrome emoji. – Jon Goodwin Aug 09 '17 at 15:19