简体   繁体   中英

Special messages on Google Cloud Messaging (PUSH to Android)

I'm able to send strings to my Android phone via the PUSH system.

Atleast on my iPhone I have noticed people sending PUSH with images, PUSH with play / stop controls (IIRC), PUSH with custom sounds.

How can I send such data to the Android phone?

My current data:

$fields = array(
    'registration_ids' => $registration_ids,
    'data' => array( "message" => $message ),
);

$message being a string.

This is the plugin I am using on the phone:

https://github.com/phonegap-build


EDIT:

After spending some time on studying this I have come into a conclusion that you only able to send a string, or an array of data.

And to have an image on the PUSH notification, you would have to send a certain message, which you intercept with your application and then proceed to alter the PUSH notification view to show an image. So there is no build-in image support, or play / stop buttons for that matter? Am I on the right tracks?

You are right. The payload you are sending from your server to your app via GCM server has no custom properties. It's just a list of key/value pairs contained within the data array, limited to 4K bytes. That's not enough for encoding an image.

When you receive this payload in your app, it's up to you to decide what to do with it, and it's your responsibility to write the code that handles the message. The most common behavior is to display a notification, and open the app when the notification is tapped. The payload could contain a URL to an image that you can download and display.

The notifications API in Android has many options, and keeps improving in new Android versions. I'm sure you can use it to achieve your desired behavior. It has nothing to do with GCM though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM