I am trying to send push notification but when code gets executed it shows invalidresgistration error. Below is the code
LoginActivity
String getToken = FirebaseInstanceIDService.onTokenRefreshs();
String getUsername = username.getText().toString();
String URL = DataHolder.TokenUrl(getUsername,getToken);
OnTokenRefresh code
public class FirebaseInstanceIDService extends FirebaseInstanceIdService {
public static String onTokenRefreshs(){
String token = FirebaseInstanceId.getInstance().getToken();
return token;
}
}
pushnotification code
$url = 'https://fcm.googleapis.com/fcm/send';
$message = array("message" => "hell man");
$xyz=array("firebasetokengoeshere I haven't included for now");
$fields = array(
'to' => json_encode($xyz),
'data' => $message
);
$headers = array(
'Authorization:key = Appkey goes here',
'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){
}
curl_close($ch);
return $result;
$message_status = send_notification($tokens, $message);
echo $message;
{"multicast_id":6744250798651355841,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
I am getting above result. How to fix this error.