How to get the delivery status of notification from fcm in springboot?

Viewed 228

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.

1 Answers

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.

Related