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.
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.
Whenever you send an notification to your user you'll send an static payload which contains an message that needs to be displayed to user when the notification is received.
When notification is received we/iOS can't do any translation of the message from one language to another.
So one solution that I can think of is, You have to find out the language setting or preference (based on his locale) of the user and then you've to store this preference in your backend. Then when you want to send the notification to that user, you can look up his language preference and convert your notification message into that particular language and set the message in payload and send it to the user.
So bottomline is, you've to do this translation of the notification message in your backend and then send it to user using notification.
HTH.
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.