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 - Server
Android - Client.
Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("TEST",
"Hello Android")
.build();
Here the plain message is .addData("TEST","Hello Android")
.
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.
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.
You could only send a very small image, as the data payload is limited to 4kB. You would also need to encode it somehow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With