שלח תמונה במטען ההודעות

FCM HTTP v1 API ו- Notifications composer תומכים בשליחת קישורי תמונה במטען של הודעת תצוגה, להורדת תמונה למכשיר לאחר מסירה. תמונות להתראות מוגבלות ל-1MB בגודלן, ולעומת זאת מוגבלות על ידי תמיכת תמונות מקורית של Android .

בנה את בקשת השליחה

בבקשת שליחת ההתראה, הגדר את האפשרות AndroidConfig הבאה:

  • notification.image המכילה את כתובת האתר של התמונה

הדוגמה הבאה של בקשת שליחת שולחת כותרת הודעה משותפת לכל הפלטפורמות, אך היא גם שולחת תמונה. להלן הערכה של האפקט החזותי במכשיר של משתמש:

ציור פשוט של תמונה בהודעת תצוגה

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);
  });

מנוחה

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"
       }
     }
   }
 }

עיין בתיעוד ההפניה של HTTP v1 לקבלת פרטים מלאים על המפתחות הזמינים בלוקים ספציפיים לפלטפורמה בגוף ההודעה.

notification מוגדרת כפי שמוצג, בקשת השליחה הזו מאפשרת ללקוח המקבל לטפל בתמונה שנמסרה במטען.