FCM:在 iOS 上显示从 Android 设备发送的表情符号或 UTF-8 文本

闪耀人

我正在尝试使用 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 - 如何在 android 中将字符串转换为 utf-8

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

WebStorm UTF-8编码不显示表情符号

将JSON文件中的UTF-8代码显示为表情符号

R中的表情符号[UTF-8编码]

使用iOS键盘输入时,表情符号在NSAttributedString中不显示,在Android中输入时,表情符号显示

UTF-8 BOM显示符号而不是文本

如何禁用iOS 8表情符号键盘?

Flutter 只呈现硬编码的表情符号。动态构造的表情符号显示为纯文本

Android textview某些表情符号未显示?

在软键盘上显示ankushsachdeva表情符号(Android)

Android 设备上的 Android FCM 要求

如何在Awesome WM中修复巨大的utf-8表情符号图标?

使用 Firebase (FCM) 在 Android 设备上发送推送通知

无法在带有大文本的Android TextView中显示Unicode字符(表情符号):“字体大小太大,无法容纳在缓存中”

为什么在JSP上UTF8文本显示为ISO-8859-1

推送通知可从FCM控制台运行,但如果从API发送,则显示“ InvalidApnsCredential”错误(仅在iOS设备上)

在React中将表情符号对象显示为文本字段或文本区域

在Android和iOS的FCM通知上启用默认声音

如何在Swift中包含表情符号的字符串中突出显示文本?

Android表情符号实现

iOS 8活力图像未显示在设备上

Android utf8上的希腊文字无法正确显示

存储并显示表情符号

iOS应用程序仅显示表情符号和英文键盘

如何在iOS上使用Freetype呈现表情符号字符?

iOS上处理的表情符号序列不一致?

如何在带有Swift的iOS 8上显示带有文本的活动指示器?

状态栏显示黑色文本,仅在iPhone 6 iOS 8模拟器上

从文本中提取表情符号

无法在TextView Android中从服务器显示表情符号