收到(新)GCM消息,但如何解析? [英] (New) GCM message received, but how to parse?

查看:138
本文介绍了收到(新)GCM消息,但如何解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的新GCM,对谷歌播放服务的一部分,不使用广口瓶为Android和服务器工作。 Android使用谷歌播放apk文件进行注册,接受,甚至发送消息。在服务器端都需要我们用GCM沟通是做一个POST到他们的服务器(如果不使用XMPP)。我简单:我的Andr​​oid应用程序寄存器,并等待消息从GCM到来。我的服务器可以与GCM沟通,我可以将邮件传递到我的Andr​​oid应用程序。

问题:我使用的是一个共同的罐子(Android和服务器),我变换和JSON的POJO对象。由于POST到GCM从我的服务器使用JSON在我的Andr​​oid收到的邮件占用了​​(至少我认为它),我认为这将让我的生活更轻松。但是,当从GCM在Android中收到的消息,我不知道如何获得消息的有效载荷,并转化为我的对象。我可以看到的信息有,但它不是我的目标(也有一些信息GCM推到它)。

我的问题是:??有没有一种方法来获得,在Android中端,有效载荷信息我已经发送到GCM服务器的方式的或者我应该没有解析JSON在Android中接收到的数据

我发送的邮件(数据为有效载荷)

  

{"registration_ids":["APA91bFdV..."],"collapse_key":null,"delay_while_idle":false,"time_to_live":2419200,"data":{"type":10,"targetVersion":-1,"message":"test味精,URL:测试网址}}

我得到了在Android中intent.getExtras()的toString()

  

捆绑[{消息=测试味精,collapse_key = do_not_collapse,   targetVersion = -1,距离= 483833987130,类型= 10,则url =测试URL}]

我倒是AP preciate你的帮助。谢谢!

解决方案
  

有没有一种方法来获得,在Android中端,有效载荷信息我已经发送到GCM服务器的方式?

而不是想JSON,认为键/值对。在你的服务器键/值对发送数据。您的应用程序接收到的数据作为额外键/值对中意图。你知道你的钥匙,所以只是检索值指出,被绑定到这些键(例如, getStringExtra(信息) getStringExtra(URL))。

  

还是应该我解析收到Android的数据,而不JSON?

接收到的数据是不是在JSON。

I am working with the "new" GCM, part of Google Play Services, that does not use jars for both Android and server. Android uses Google Play apk to register, receive and even send messages. At server side all we need to communicate with GCM is to do a POST to their server (if not using XMPP). I have all set: my Android app registers and waits for messages coming from GCM. My server can communicate with GCM and I'm able to deliver messages to my Android app.

The problem: I'm using a common jar (Android and server) with POJO objects that I transform to and from JSON. Since POST to GCM from my server uses JSON and received messages in my Android uses too (at least I believe it does), I thought it would make my life easier. But when receiving a message from GCM in Android I don't know how to get message's payload and transform to my objects. I can see the informations there but it's not my object (there are some information GCM push into it).

My question is: Is there a way to get, in Android end, payload information the way I've sent to GCM server? Or should I parse received data in Android without JSON?

Message I sent ("data" is payload)

{"registration_ids":["APA91bFdV..."],"collapse_key":null,"delay_while_idle":false,"time_to_live":2419200,"data":{"type":10,"targetVersion":-1,"message":"test msg","url":"test url"}}

What I got in Android intent.getExtras().toString()

Bundle[{message=test msg, collapse_key=do_not_collapse, targetVersion=-1, from=483833987130, type=10, url=test url}]

I'd appreciate your help. Thanks!

解决方案

Is there a way to get, in Android end, payload information the way I've sent to GCM server?

Rather than thinking "JSON", think "key/value pairs". Your server sends data in key/value pairs. Your app receives that data as key/value pairs in the extras in the Intent. You know what your keys are, so just retrieve the values out of the extras that are tied to those keys (e.g., getStringExtra("message"), getStringExtra("url")).

Or should I parse received data in Android without JSON?

The received data is not in JSON.

这篇关于收到(新)GCM消息,但如何解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆