好吧,我到处都找过了,但找不到答案。
我已经在我的 Android 应用程序中实现了推送通知,并且当应用程序处于活动状态(前台或后台)时一切正常,但是如果我关闭应用程序,我将停止接收通知。
这是我发送通知的 php 代码。
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;
}