[英]How can I send a notification?
I am developing an Android App that communicates with a server. 我正在开发与服务器通信的Android应用程序。 How can I send a notification from my server to my Android App without the use of C2DM? 如何在不使用C2DM的情况下从服务器向Android应用发送通知? Are Sockets a good solution? 套接字是一个好的解决方案吗? What are other alternatives? 还有哪些其他选择?
I'd suggest you to develop a webservice preferably with JSON which is easy to handle. 我建议您最好使用易于处理的JSON开发一个Web服务。 This server client architecture will hellp you to send and receive any kind of data (ranges from raw text to images or even video) 这种服务器客户端体系结构会欺骗您发送和接收任何类型的数据(范围从原始文本到图像甚至是视频)
Check out C# webservices. 查看C#Web服务。 That are very easy to start than the PHP services IMHO. 比起PHP服务恕我直言,这非常容易启动。
Depends on what you want to do. 取决于您要做什么。
have you thought on how does the server identifies the client to send the message ? 您是否考虑过服务器如何识别客户端以发送消息? In this case the android phone ? 在这种情况下android手机?
With http you would need the client to "request" this notification. 使用http,您需要客户端“请求”此通知。
The closest thing to an actual notification would be to have a socket connection, which the client would connect to the server. 与实际通知最接近的是建立套接字连接,客户端将其连接到服务器。 But then would require an existent connection between the two. 但这将要求两者之间存在连接。 If this is ok for what you are doing, then go ahead if you really want to avoid C2DM. 如果您的工作没问题,那么如果您真的想避免使用C2DM,请继续进行。
But, using C2DM allows your server to send notification to devices without a need for a request or direct connection from the client. 但是,使用C2DM可使您的服务器将通知发送到设备,而无需来自客户端的请求或直接连接。 The only thing you need to do is pass the identification of the device to your third-party server given when you authenticate with google's C2DM. 您唯一需要做的就是将设备的标识传递给您在通过Google的C2DM进行身份验证时提供的第三方服务器。 After that, you just push notification data to C2DM and google delivers the notification for you. 之后,您只需将通知数据推送到C2DM,Google就会为您发送通知。
I've used MQTT for providing push notifications on Android and it's proved to be a good, reliable, low power solution. 我已经使用MQTT在Android上提供推送通知,并且事实证明这是一个很好,可靠的低功耗解决方案。
Some links to support my case / get you started: 一些支持我的案例的链接/帮助您入门:
http://mqtt.org/ http://mqtt.org/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.