1

Below is my code in spring boot.

private void sendNotification(FCMMessageRequestDTO fcmMessageRequestDTO) {
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.set("Authorization", fcmAuthorizationKey);
    headers.add("Content-Type", "application/json");
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    HttpEntity<FCMMessageRequestDTO> request = new HttpEntity<>(fcmMessageRequestDTO, headers);
    restTemplate.postForObject(fcmMessageUrl, request, Object.class);
}

Here how can I check the status of delivery of notification to device.

Can someone help me out in this.

Rahul
  • 493
  • 3
  • 7
  • 25

1 Answers1

1

FCM no longer provides you status of the delivery of notification to the device. It only gives you an acknowledgement in the response of your POST request that the message has been received by the FCM system. Assign your response to a variable and check the output.

String response = restTemplate.postForObject(fcmMessageUrl, request, Object.class);
System.out.println(response);

Also, I'll strongly suggest you to use the FCM admin SDK in your project.

dope
  • 303
  • 4
  • 14
  • is there any reason why are you strongly suggesting on fcm admin sdk. Will it help me to get the delivery status of notification to device? – Rahul Oct 08 '21 at 06:01
  • No, I already mentioned in my answer that FCM no longer gives you delivery status of your notification, the reason I'm suggesting SDK is because it is much easier to use and saves you a lot of code and also a recommended way by FCM itself. https://firebase.google.com/docs/cloud-messaging/server#choosing-a-server-option – dope Oct 08 '21 at 07:17