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

标签 android ios firebase utf-8 push-notification

我正在尝试使用 Firebase 发送推送通知(表情符号或 UTF-8 文本)。 在 iOS 和 iOS 之间,在 Android 和 Android 之间以及从 iOS 到 Android,它运行良好。但仅从 Android 到 iOS,它不起作用并且文本已损坏。

我使用 URLEncoder.encode 函数进行 UTF-8 编码。 这是发送代码。

            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();

请帮帮我。提前致谢。

最佳答案

终于找到解决办法了。 Android - How to Convert String to utf-8 in android

感谢@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;
}
}

关于android - FCM : Displaying emoji or UTF-8 text on iOS that is sent from Android device,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48239347/

相关文章:

android - 如何使用真实设备测量移动浏览器渲染时间

ios - 如何设置 UICollectionView 填充 UIEdgeInsets

python - 导入错误 : Failed to import the Cloud Firestore library for Python

启用 Firebase DB 持久性后,Swift 3 发现 nil

firebase - GeoFire 在移动时检索一定范围内的所有查询。

java - 使用 md5 哈希后使用 java.util.UUID 是一个不错的选择吗?

android - 尝试在 android 中添加两个 setContentView 时出现空指针异常

ios - CCAdvancedMenu boundaryRect

java - Android Camera2 - 当 E/Camera 不可用时回调拦截 E/Camera 错误(即用户自拍)

android - Android 的 Like 按钮仅适用于 App 管理员