Die FCM HTTP v1 API und der Notifications Composer unterstützen das Senden von Bildlinks in der Nutzlast einer Benachrichtigung, damit das Bild nach der Zustellung auf das Gerät heruntergeladen werden kann. Bilder für Benachrichtigungen dürfen maximal 1 MB groß sein und unterliegen ansonsten den Einschränkungen der nativen Android-Bildunterstützung.
Sendeanfrage erstellen
Legen Sie in Ihrer Anfrage zum Senden von Benachrichtigungen die folgende AndroidConfig-Option fest:
notification.image
mit der Bild-URL
Im folgenden Beispiel wird eine Anfrage gesendet, die einen gemeinsamen Benachrichtigungstitel an alle Plattformen sendet, aber auch ein Bild. Hier sehen Sie eine ungefähre Darstellung des visuellen Effekts auf dem Gerät eines Nutzers:
Node.js
const topicName = 'industry-tech';
const message = {
notification: {
title: 'Sparky says hello!'
},
android: {
notification: {
imageUrl: 'https://foo.bar.pizza-monster.png'
}
},
apns: {
payload: {
aps: {
'mutable-content': 1
}
},
fcm_options: {
image: 'https://foo.bar.pizza-monster.png'
}
},
webpush: {
headers: {
image: 'https://foo.bar.pizza-monster.png'
}
},
topic: topicName,
};
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
REST
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"topic":"industry-tech",
"notification":{
"title":"Sparky says hello!",
},
"android":{
"notification":{
"image":"https://foo.bar/pizza-monster.png"
}
},
"apns":{
"payload":{
"aps":{
"mutable-content":1
}
},
"fcm_options": {
"image":"https://foo.bar/pizza-monster.png"
}
},
"webpush":{
"headers":{
"image":"https://foo.bar/pizza-monster.png"
}
}
}
}
Die vollständigen Details zu den Schlüsseln, die in plattformspezifischen Blöcken im Nachrichtentext verfügbar sind, finden Sie in der HTTP v1-Referenzdokumentation.
Wenn notification
wie gezeigt festgelegt ist, kann der empfangende Client mit dieser Sendeanfrage das in der Nutzlast bereitgestellte Bild verarbeiten.