Ok so i have looked everywhere and I can't find an answer to this. I have implemented the push notification in my Android app and everything works fine while the app is alive (Foreground or background), however if I close the app I stop receiving notifications. Here is the php code where I send the notification.
public static function sendNotification($token){
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'notification' => array("title" => "Test","body" => "Test Message","icon" => "default","sound" => "default"),
"data" => "test message",
'to' => $token
);
$headers = array(
'Authorization:key = AIzaSyAKHM3MoMACjmeVK46TDg8-rTj1KoVjzWs',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
$result = curl_exec($ch);
if($result === FALSE) {
throw new errorSendingNotification();
}
curl_close($ch);
// Result returns this
// {"multicast_id":8978533958735781479,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1468627796530714%7c0e4bee7c0e4bee"}]}
return $result;
}