different language notification Firebase

Viewed 5764

How can I send a notifications if the device is in English and an other notification for all other language ?

I tried to make two different audience but the two audience are empty.

2 Answers

The best approach for sending push notifications using FCM in multiple language is to encode the message(of any language) in UTF-8 format and send it.

In the android end the message will come like this.

"[30, 45, 13, 54,12, 33]" **these numbers may come in negetive value

Now decode the JSONArray into String is the only work remained.

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;
}

You will get the string in your language.Hope this helps.

Related