Reputation: 55
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 k and my problem is if I want to put this emoji for example 😒 the ascii I got is �� I don't know how to put this ascii in the xml .. any help?
Upvotes: 2
Views: 1812
Reputation: 9153
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
Upvotes: 2