Display emojis in notification content

What is the best practice for sending emoji notifications, what should the payload look like?

Is there any parsing in the application for emojis to display correctly, or does it just work out of the box if emojis is formatted correctly?

I tried sending this emoji and tried various formats: http://www.charbase.com/1f602-unicode-face-with-tears-of-joy

the payload looked something like this:

 "payload": {
  "message": "U+1F602 \ud83d\ude02 😂 😂 f0 9f 98 82",
  "title": "Hello",
  "id": 123,
}

This is how the application displays a notification:

@Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
                GCMPayload payload = new GCMPayload(
                        extras.getString("title"),
                        extras.getString("message"),
                        Strings.convertToLong(extras.getString("id")),
                );

                sendNotification(this, payload);
            }
        }

And in the sendNotification method, the text of the notification content is set as follows:

 NotificationCompat.Builder builder =
                new NotificationCompat.Builder(context)
                        .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                        .setContentTitle(payload.getTitle())
                        .setContentText(payload.getMessage())
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(payload.getMessage()));

Emojis are not displayed, codes are displayed instead. What encoding should I use? What else needs to be done to correctly display emojis?

+4
2

hardcoding onMessageReceived :

String title = "Title \uD83D\uDE00";
...
.setContentTitle(title)
...

Title πŸ˜€.

, title. - :

0 = 'T' 84
1 = 'i' 105
2 = 't' 116
3 = 'l' 108
4 = 'e' 101
5 = ' ' 32
6 = '\uD83D' 55357
7 = '\uDE00' 56832

Android . , , , .

Google, :

Sender sender = new Sender("YOUR API KEY");
Message.Builder builder = new Message.Builder();
builder.addData("title", "Title \uD83D\uDE00");
sender.send(builder.build(), "YOUR DEVICE TOKEN", 5);

. emojis , , emoji .

+1

:

<string name="string_title">This is a emoji example <U+1F642></string>

Android Studio 3.0 emoji:

Emoji

:

Emoji

+1

Source: https://habr.com/ru/post/1622815/


All Articles