Using Emoji in Android Push Notification

May 01, 2016

Reading time ~1 minute

Nowadays, it is so popular to send push notifications to clients including some sweet emojis for drawing attention and increasing the push notification click probability.

If you want to use emojis by holding your text in a string variable or constant, you can use directly in the following format.

String textWithEmoji = "This is your text with smile, \ud83d\ude03";

That’s ok, but where could we find these unicode form of emojis’?

http://www.charbase.com/block/emoticons

After clicking one of those emojis in the list, you can get and use “Java Escape” form directly.

Ok, this was really easy, but what if you want to get this string from strings.xml file. Bad news is that you can not use directly as “\ud83d\ude03”. After some investigation I have decided to use url encoded form of emojis in strings.xml and decode it before setting my notification’s title ot message.

On the same page you can see the url encoded form of emoji as follows :

q=%F0%9F%98%83

Just remove the “q=” part and store in the strings.xml file as shown below:

<string name="notification_emoji_smile">%F0%9F%98%83</string>

After reading the value from strings xml, you need to decode it. You can also combine it with another string from a variable or strings.xml.

String emojiString = context.getString(R.string.notification_emoji_smile);
String decodedEmoji = URLDecoder.decode(emojiString, "UTF-8");
String notificaitonMessage = "Hi guys, " + decodedEmoji;

Let’s say you found some emojis from another web site like this :

https://www.piliapp.com/emoji/list/

No problem, you can URL encode it and apply the same method above. You can use the following web site to URL encode emoji.

http://www.freeformatter.com/url-encoder.html#ad-output

That’s all, I wish happy emoji usages for everyone :)

Depending on an aar library includes transitive dependencies in a maven project

Depending on an aar library includes transitive dependencies in a maven project Continue reading