简体   繁体   English

Google Cloud Messaging上的特殊消息(PUSH到Android)

[英]Special messages on Google Cloud Messaging (PUSH to Android)

I'm able to send strings to my Android phone via the PUSH system. 我可以通过PUSH系统将字符串发送到我的Android手机。

Atleast on my iPhone I have noticed people sending PUSH with images, PUSH with play / stop controls (IIRC), PUSH with custom sounds. 在我的iPhone上,我注意到人们发送带有图像的按钮,具有播放/停止控件(IIRC)的按钮,具有自定义声音的按钮。

How can I send such data to the Android phone? 如何将此类数据发送到Android手机?

My current data: 我当前的数据:

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

$message being a string. $ message是一个字符串。

This is the plugin I am using on the phone: 这是我在电话上使用的插件:

https://github.com/phonegap-build 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. 为了在PUSH通知上显示图像,您必须发送一条消息,您会在应用程序中拦截该消息,然后继续更改PUSH通知视图以显示图像。 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. 您通过GCM服务器从服务器发送到应用程序的有效负载没有自定义属性。 It's just a list of key/value pairs contained within the data array, limited to 4K bytes. 它只是data数组中包含的键/值对的列表,限制为4K字节。 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. 有效负载可能包含您可以下载和显示的图像的URL。

The notifications API in Android has many options, and keeps improving in new Android versions. Android中通知API有很多选项,并且在新的Android版本中不断改进。 I'm sure you can use it to achieve your desired behavior. 我确定您可以使用它来实现所需的行为。 It has nothing to do with GCM though. 它与GCM无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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