简体   繁体   English

如何使用Android代码中的GCM CCS进行上游消息传递服务?

[英]How to do upstream messaging service using GCM CCS from Android code?

I am trying to implement a messaging service using GCM's CCS...I have already implemented GCM in normal way where I used a third-party server and browser key with GCM Sender id to send notification to devices, which works perfectly. 我正在尝试使用GCM的CCS实现消息传递服务...我已经以常规方式实现了GCM,在该方法中,我使用了带有GCM Sender ID的第三方服务器和浏览器密钥将通知发送到设备,效果很好。

I have tried implementing CCS using the following link 我尝试使用以下链接实施CCS

Tutorial 教程

Which has two project one is for Android and another one for Java. 其中有两个项目,一个用于Android,另一个用于Java。 I am not worried for the server application for time being because I can use PHP features too. 我暂时不担心服务器应用程序,因为我也可以使用PHP功能。 However I am not finding a way where Android application is connecting with server application in the code and other examples have same unrealistic ending to the project. 但是,我没有找到代码中Android应用程序与服务器应用程序连接的方式,其他示例对项目也有不切实际的结尾。 If at all I can send the registrationId to my server using HTTP connection, how would I able to send upstream message to GCM-CCS from application? 如果完全可以使用HTTP连接将registrationId发送到我的服务器,我如何从应用程序向GCM-CCS发送上游消息?

I want that one device will send a message to CCS Application and that message will be broadcast to all registered devices including the sender. 我希望一台设备将消息发送到CCS应用程序,并且该消息将广播到包括发件人在内的所有已注册设备。

CCS广播

The following link for tutorial is a bogus link too, I don't understand what its trying to do. 以下教程链接也是虚假链接,我不知道该尝试执行的操作。

Another Tutorial 另一个教程

Google must provide a clear representation about CCS-GCM. Google必须提供有关CCS-GCM的清晰陈述。

Please refer this link - 请参考此链接-

http://developer.android.com/reference/org/apache/http/client/methods/HttpPost.html http://developer.android.com/reference/org/apache/http/client/methods/HttpPost.html

a small tutorial- http://www.androidhive.info/2011/10/android-making-http-requests/ 一个小教程-http ://www.androidhive.info/2011/10/android-making-http-requests/

for sending messages from app to backend , you can use json encoding . 为了从应用程序向后端发送消息,您可以使用json编码。 and POST parms to url or yours server , do something like this - 和POST parms到url或您的服务器,执行以下操作-

// Building Parameters

                List<NameValuePair> params = new ArrayList<NameValuePair>();



                params.add(new BasicNameValuePair("message", post_message));

                Log.d("request!", "starting");



                //Posting user data to script

                JSONObject json = jsonParser.makeHttpRequest(

                        POST_URL, "POST", params);

Where JSONObject is yours json parser Sir JSONObject是您的json解析器

a good json parser tutorial - http://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/ 一个好的json解析器教程-http: //eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/

As per yours edit , After yours backend recieves the messages encoded in json , save them in database and then finally use GCM to send messages to all the registered device 根据您的编辑,在您的后端收到以json编码的消息后,将它们保存在数据库中,然后最终使用GCM将消息发送到所有已注册的设备

I think you need to use an XMPP connection to send upstream messages. 我认为您需要使用XMPP连接来发送上游消息。 See https://developers.google.com/cloud-messaging/ccs#upstream for a description of upstream messaging along with sample code. 请参阅https://developers.google.com/cloud-messaging/ccs#upstream ,以获取上游消息传递以及示例代码的说明。 (This is also where I learned that you need to use XMPP instead of HTTP. Sorry I don't have more specific answers to offer at the moment, I'm still working out how to do this myself. (这也是我了解到您需要使用XMPP而不是HTTP的地方。抱歉,我目前没有更具体的答案,我仍然在自己解决这个问题上。

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

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