Push notification with the image is not showing for the first notification. But after the subsequence notification, the image with text is showing in the Android app.
I have added the notification receiving code in the Android app. I have attached the PHP page for push notification.
$deviceToken = devicetoken;
$mob_type="Android";
if($mob_type=='Android'){
$apiKey="androidapikey";
}
else {
$apiKey="iosapikey";
}
$message = [
'to' => $deviceToken,
'notification' => [
'title' => 'test',
'body' => 'Notification with image',
'picture' => 'https://domain name/test_img.png',
],
];
$headers = [
'Authorization: key=' . $apiKey,
'Content-Type: application/json',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
$result = curl_exec($ch);
curl_close($ch);
// Handle the result as needed
echo $result;
Kindly give some solution. I have done all the solution from the chatgpt. Anyother solution?




