[WARNING]: This project is not actively being maintainted. You may use vdurmont/emoji-java as an alternative.
Java library to convert short codes, html entities to emojis and vice-versa. Also supports parsing emoticons, surrogate html entities.
Inspired by vdurmont/emoji-java, emoji4j adds more goodies and helpers to deal with emojis. The emoji data is based on the database from github/gemoji and ASCII emoticons data from wooorm/emoticon.
Stable:
<dependency>
<groupId>com.kcthota</groupId>
<artifactId>emoji4j</artifactId>
<version>6.0</version>
</dependency>
Get emoji by unicode, short code, decimal or hexadecimal html entity
Emoji emoji = EmojiUtils.getEmoji("🐭"); //get emoji by unicode character
EmojiUtils.getEmoji("blue_car").getEmoji(); //returns 🚙
EmojiUtils.getEmoji(":blue_car:").getEmoji(); //also returns 🚙
EmojiUtils.getEmoji("🐭").getEmoji(); //returns 🐭
EmojiUtils.getEmoji("🐭").getEmoji(); //also returns 🐭
EmojiUtils.getEmoji(":)").getEmoji(); //returns 😃
EmojiUtils.getEmoji("��").getEmoji(); //returns 😁
Conversion from unicode, short code, hexadecimal and decimal html entities is pretty easy.
Emoji emoji = EmojiUtils.getEmoji("🐭");
emoji.getEmoji(); //returns 🐭
emoji.getDecimalHtml(); //returns 🐭
emoji.getHexHtml(); //return 🐭
emoji.getAliases(); //returns a collection of aliases. ["mouse"]
Verifies if the passed string is an emoji character
EmojiUtils.isEmoji("🐭"); //returns true
EmojiUtils.isEmoji("blue_car"); //returns true
EmojiUtils.isEmoji(":coyote:"); //returns false
EmojiUtils.isEmoji("🐭"); //returns true
EmojiUtils.isEmoji("🐭"); //returns true
Emojifies the passed string
String text = "A :cat:, :dog: and a :mouse: became friends<3. For :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.emojify(text); //returns A 🐱, 🐶 and a 🐭 became friends❤️. For 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
String text = "A 🐱, 🐶 and a :mouse: became friends. For the :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:."
EmojiUtils.emojify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
String text=":):-),:-):-]:-xP=*:*<3:P:p,=-)";
EmojiUtils.emojify(text); //returns 😃😃😅😃😶😝😗😗❤️😛😛😅
Converts unicode characters in text to corresponding decimal html entities
String text = "A :cat:, :dog: and a :mouse: became friends. For the :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.htmlify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
String text = "A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰."
EmojiUtils.htmlify(text); //also returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
Converts unicode characters in text to corresponding decimal hexadecimal html entities
String text = "A :cat:, :dog: and a :mouse: became friends. For the :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.hexHtmlify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
String text = "A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰."
EmojiUtils.hexHtmlify(text); //returns A 🐱, 🐶 and a 🐭 became friends. For the 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.
Converts unicode characters in text to corresponding decimal surrogate html entities
String text = "😃";
EmojiUtils.htmlify(text, true); //returns ��
##shortCodify
String text = "A 🐱, 🐶 and a 🐭 became friends❤️. For 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.";
EmojiUtils.shortCodify(text); //returns A :cat:, :dog: and a :mouse: became friends:heart:. For :dog:'s birthday party, they all had :hamburger:s, :fries:s, :cookie:s and :cake:.
text = ":):-),:-):-]:-xP=*:*<3:P:p,=-)";
EmojiUtils.shortCodify(text); //returns :smiley::smiley::sweat_smile::smiley::no_mouth::stuck_out_tongue_closed_eyes::kissing::kissing::heart::stuck_out_tongue::stuck_out_tongue::sweat_smile:
Removes unicode emoji characters from the passed string
String emojiText = "A 🐱, 🐱 and a 🐭 became friends❤️. For 🐶's birthday party, they all had 🍔s, 🍟s, 🍪s and 🍰.";
EmojiUtils.removeAllEmojis(emojiText);//"A , and a became friends. For 's birthday party, they all had s, s, s and .
Counts emojis in a String
String text = "A 🐱, 🐶, :coyote: and a :mouse: became friends. For :dog:'s birthday party, they all had 🍔s, :fries:s, :cookie:s and :cake:.";
EmojiUtils.countEmojis(text); //returns 8
Add stop words to filter out certain words from emoji conversion
String text = "http://www.github.com and https://www.google.com are awesome :-).";
EmojiManager.addStopWords("http://", "https://");
EmojiUtils.emojify(userText) //returns http://www.github.com and https://www.google.com are awesome 😃.
Copyright 2016 Krishna Chaitanya Thota (kcthota@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
github/gemoji's license:
octocat, squirrel, shipit Copyright (c) 2013 GitHub Inc. All rights reserved.
bowtie, neckbeard, fu Copyright (c) 2013 37signals, LLC. All rights reserved.
feelsgood, finnadie, goberserk, godmode, hurtrealbad, rage 1-4, suspect Copyright (c) 2013 id Software. All rights reserved.
trollface Copyright (c) 2013 whynne@deviantart. All rights reserved.
All other images Copyright (c) 2013 Apple Inc. All rights reserved.
wooorm/emoticon's license:
Copyright (c) 2014 Titus Wormer tituswormer@gmail.com