mori mori - 1 year ago 1468
Android Question

How to implement firebase cloud messaging in server side?

After migrating to Firebase, i tested sending notification by using the firebase console it works fine, but i need a daily notification on a specific time so instead of using the firebase console i use my former cron job to send notification daily. I changed
but my device doesn't receive any notification.

Is there any way to solve this? Or did I miss anything? my cron job is working fine for my devices that is still using GCM.

Here's my code

function sendNotificationFCM($apiKey, $registrationIDs, $messageText,$id) {

$headers = array(
'Authorization:key=' . $apiKey

$message = array(
'registration_ids' => $registrationIDs,
'data' => array(
"message" => $messageText,
"id" => $id,

$ch = curl_init();

curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => json_encode($message)

$response = curl_exec($ch);

return $response;


Answer Source

I added notification object in my json. I found out that in my remoteMessage.getNotification().getBody() it returns null that's why it doesn't receive any notification send by my cron.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download