FCM:在Android设备上发送的iOS上显示表情符号或UTF-8文本 [英] FCM: Displaying emoji or UTF-8 text on iOS that is sent from Android device

查看:434
本文介绍了FCM:在Android设备上发送的iOS上显示表情符号或UTF-8文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

推荐答案

我终于找到了解决方案. Android-如何在Android中将字符串转换为utf-8

I finally found the solution out. 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;
}
}

这篇关于FCM:在Android设备上发送的iOS上显示表情符号或UTF-8文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆