1

I am sending notifications from the browser using PHP to an android device. when I start app after logout notifications are coming but if I kill app notifications are not coming. any solution for this.

 public function send_android($target, $fields) {
    $apiKey = 'XXXXXXXXX';
    $headers = array("Content-Type:" . "application/json", "Authorization:key=" . $apiKey);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    curl_close($ch);
}
asiby
  • 3,229
  • 29
  • 32
Shadab
  • 19
  • 3
  • Possible duplicate of [Push Notifications when app is closed](https://stackoverflow.com/questions/24313539/push-notifications-when-app-is-closed) – M. Eriksson Mar 04 '19 at 06:26

1 Answers1

2

You need to send extra key in fields array named "priority" and value will "high". So your fields array will be same as ...

$fields = array('to' => $token, 'notification' => $notification,'priority'=>'high');
Riajul Islam
  • 1,425
  • 15
  • 19