I am implementing FCM notifications in Android, but how does notifications differ depending on the app status (background vs. foreground)?
Update 2019 August.
[wasted couple of days just because py doesn't support latest changes for notification]
Just add image=url into your notification object.
It works in Native Android. Just add image into notification object. Also please note that in Python library image field doesn't exist. [As of Aug 19] https://github.com/firebase/firebase-admin-python
I used PHP and this library https://github.com/kreait/firebase-php/ Its super simple and more importantly, it works for big image notification when app is in background or has been killed.
Code:
withServiceAccount($serviceAccount)->create();
$messaging = $firebase->getMessaging();
// this works when app is closed or in bg
$notification = Notification::fromArray([
'title' => $title,
'body' => $body,
'image' => $imageUrl,
]);
// for foreground process
$data = [
'image' => $imageUrl,
'news_id' => $news_id,
];
$topic = 'default_topic1';
$message = CloudMessage::withTarget('topic', $topic)
->withNotification($notification) // optional
->withData($data);
$messaging->send($message);
print_r($message);