FCM: Displaying emoji or UTF-8 text on iOS that is sent from Android device

ShineMan

I'm trying to send a push notification(emoji or UTF-8 text ) using Firebase. Between iOS and iOS, between Android and Android and from iOS to Android, it works well. But only from Android to iOS, it doesn't work and the texts are broken.

I used URLEncoder.encode function for UTF-8 encoding. Here is the code for sending.

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("to", mCurrentUser.token);

            JSONObject notificationObject = new JSONObject();
            notificationObject.put("title", title);
            notificationObject.put("body", URLEncoder.encode(mMessage.text, "UTF-8"));

            notificationObject.put("content_available", true);

            jsonObject.put("notification", notificationObject);

            DataOutputStream wr = new DataOutputStream(httpURLConnection.getOutputStream());
            wr.writeBytes(jsonObject.toString());
            wr.flush();

Please help me. Thanks in advance.

ShineMan

I finally found the solution out. Android - How to Convert String to utf-8 in android

Thanks to @Paras.

public class StringFormatter {

// convert UTF-8 to internal Java String format
public static String convertUTF8ToString(String s) {
    String out = null;
    try {
        out = new String(s.getBytes("ISO-8859-1"), "UTF-8");
    } catch (java.io.UnsupportedEncodingException e) {
        return null;
    }
    return out;
}

// convert internal Java String format to UTF-8
public static String convertStringToUTF8(String s) {
    String out = null;
    try {
        out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
    } catch (java.io.UnsupportedEncodingException e) {
        return null;
    }
    return out;
}
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

FCM messages not reaching device when sent from server

From Dev

FCM messages not reaching device when sent from server

From Java

How to set UTF-8 encoding when displaying text from MySQL (JDBC,JSP)

From Dev

Displaying UTF-8 codes from JSON file as Emoticons

From Dev

Getting a utf-8 encoded string from a database, then displaying in a webview

From Dev

Displaying MapView in an android device

From Dev

Android FCM requirements on Android device

From Dev

Emoji in R [UTF-8 encoding]

From Dev

Emoji from android to web

From Dev

sms sent from java app does not appear on android device

From Dev

FCM Notifications Not Displaying When App Is Terminated iOS

From Dev

Notification not sent to android wear device

From Dev

iOS - error parsing JSON created using UTF8Encoding and sent as C string

From Dev

iOS UITextView with attributed text not displaying from top of view

From Dev

iOS UITextView with attributed text not displaying from top of view

From Dev

How to disable iOS 8 emoji keyboard?

From Dev

Why push notification directed to specific iOS device from Web API through Firebase FCM does not arrive?

From Dev

Special characters UTF8 not displaying in safari

From Dev

Terminal not displaying UTF-8 character(s)

From Dev

Mojolicious template displaying invalid UTF-8

From Dev

android itext using assets fonts and utf-8 text

From Dev

Greek text on android utf8 not show properly

From Dev

UTF-8 characters displaying incorrectly in PHP (when outputting result from MYSQL)

From Dev

Ionic: Displaying web content on iOS device

From Dev

How to make the output from Text::CSV utf8?

From Dev

Extracting text from InputStreamReader not working in UTF-8

From Dev

Launch Screen not displaying iOS 8

From Dev

Android Application not displaying on device as it does in Android Studio

From Dev

Android Application not displaying on device as it does in Android Studio

Related Related

  1. 1

    FCM messages not reaching device when sent from server

  2. 2

    FCM messages not reaching device when sent from server

  3. 3

    How to set UTF-8 encoding when displaying text from MySQL (JDBC,JSP)

  4. 4

    Displaying UTF-8 codes from JSON file as Emoticons

  5. 5

    Getting a utf-8 encoded string from a database, then displaying in a webview

  6. 6

    Displaying MapView in an android device

  7. 7

    Android FCM requirements on Android device

  8. 8

    Emoji in R [UTF-8 encoding]

  9. 9

    Emoji from android to web

  10. 10

    sms sent from java app does not appear on android device

  11. 11

    FCM Notifications Not Displaying When App Is Terminated iOS

  12. 12

    Notification not sent to android wear device

  13. 13

    iOS - error parsing JSON created using UTF8Encoding and sent as C string

  14. 14

    iOS UITextView with attributed text not displaying from top of view

  15. 15

    iOS UITextView with attributed text not displaying from top of view

  16. 16

    How to disable iOS 8 emoji keyboard?

  17. 17

    Why push notification directed to specific iOS device from Web API through Firebase FCM does not arrive?

  18. 18

    Special characters UTF8 not displaying in safari

  19. 19

    Terminal not displaying UTF-8 character(s)

  20. 20

    Mojolicious template displaying invalid UTF-8

  21. 21

    android itext using assets fonts and utf-8 text

  22. 22

    Greek text on android utf8 not show properly

  23. 23

    UTF-8 characters displaying incorrectly in PHP (when outputting result from MYSQL)

  24. 24

    Ionic: Displaying web content on iOS device

  25. 25

    How to make the output from Text::CSV utf8?

  26. 26

    Extracting text from InputStreamReader not working in UTF-8

  27. 27

    Launch Screen not displaying iOS 8

  28. 28

    Android Application not displaying on device as it does in Android Studio

  29. 29

    Android Application not displaying on device as it does in Android Studio

HotTag

Archive