Skip to Content
0
Jan 09, 2023 at 12:44 PM

FCM notification in Arabic coming as ????

130 Views Last edit Jan 09, 2023 at 04:05 PM 2 rev

FCM notification is not working in arabic from code but while sending the same request from postman, it works as expected. Any help will be much appreciated.

public void testSendSMS() throws IOException {   

 CloseableHttpClient client = HttpClients.createDefault();

   HttpPost httpPost = new HttpPost("https://fcm.googleapis.com/fcm/send");

    log.info("httpPost :: " + httpPost);

   String msg = "تم تقديم الطلب برمز {0} بنجاح";

    JSONObject body = new JSONObject();

   body.put("to", "abc");

   body.put("priority", "high");

    JSONObject notification = new JSONObject();

    notification.put("title", URLEncoder.encode(msg, StandardCharsets.UTF_8));

    notification.put("body", msg);

    notification.put("sound", "default");

    JSONObject data = new JSONObject();

    data.put("Key-1", "JSA Data 1");

    data.put("Key-2", "JSA Data 2");

    body.put("notification", notification);

    body.put("data", data);

   StringEntity entity = new StringEntity(body.toString());

    httpPost.setEntity(entity);

    httpPost.setHeader("Content-type", "application/json");

    httpPost.setHeader("Authorization", "key=yyy");

    log.info("json :: " + json);

    CloseableHttpResponse response = client.execute(httpPost);

    log.info("response :: " + response);

    client.close();
}