GCM send image instead of message

后端 未结 4 1002
无人共我
无人共我 2020-12-11 05:10

I\'m an Android newbie, and I\'m using Google GCM to send a plain text message. Is it possible to send an image file as stream or by some other method?

Java -

相关标签:
4条回答
  • 2020-12-11 05:39

    You can only send key/value pairs with total size up to 4096 bytes. Even if you manage to encode an image within a string parameter, it would be a tiny image. An alternative is to send a string that refers to the image location, either a local file name on your device or a URL that you can access to download the image when you handle the notification.

    0 讨论(0)
  • 2020-12-11 05:42

    You could only send a very small image, as the data payload is limited to 4kB. You would also need to encode it somehow.

    0 讨论(0)
  • 2020-12-11 06:00

    I wrote two blogs posts on how to do this:

    Tutorial: Using AirBop to Send Images in the Message Payload which shows you how to do it by base64 encoding the image.

    Tutorial: Using AirBop to Push Images for BigPictureStyle Notifications which shows you how to push image urls and then download the image.

    Both tutorials use AirBop as the Application server, but the client code is separate from that and can be used generically.

    0 讨论(0)
  • 2020-12-11 06:00

    Okay let's think about the bigger picture here. As everyone has said it is very hard or impossible to send an image using gcm unless you have a tiny image. Another technique is to send it in parts but hey that's annoying no one wants to code that all out. My suggestion is to code the server to store passkeys and image credentials which can be sent to the device. The device then queries the server with the credentials to get an image download. This technique is similar to the theory of using push to notify the device that new data is available on the server. It was originally used to make a server that uses as little push as possible but it is adpted in this case to be a placeholder for sending big data.

    0 讨论(0)
提交回复
热议问题