[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 ([email protected])
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 [email protected]