代码之家  ›  专栏  ›  技术社区  ›  Max0u

不同语言通知Firebase

  •  7
  • Max0u  · 技术社区  · 9 年前

    2 回复  |  直到 9 年前
        1
  •  1
  •   iamyogish    9 年前

    无论何时向用户发送通知,都会发送 静态有效载荷 其中包含在收到通知时需要向用户显示的消息。

    收到通知后,我们/iOS无法将消息从一种语言翻译成另一种语言。

        2
  •  -1
  •   AkashToSky    6 年前

    在android端,消息将是这样的。

    "[30, 45, 13, 54,12, 33]"

    现在,将JSONArray解码为字符串是剩下的唯一工作。

    private static String getStringFromJSONArray(String text)
    {
        String decodedText = "";
        Gson converter = new Gson();
        Type type = new TypeToken<List<Byte>>(){}.getType();
        List<Byte> iList = converter.fromJson(text, type);
    
        byte[] bytes = new byte[iList.size()];
    
        for(int i = 0; i<iList.size(); i++)
        {
            bytes[i] = iList.get(i);
        }
    
        decodedText = new String(bytes, StandardCharsets.UTF_8);
        return decodedText;
    }
    

    您将获得您语言中的字符串。希望这有帮助。