详细请点击:http://www.verydemo.com/demo_c131_i26919.html
这些天一直在琢磨如何在android device上实现一套Push功能,也google很多资料,看似无外乎以下三个方案(以下转载):
- Poll? The name obviously tells you that it’s really not even push. The idea here is to periodically poll the server for new messages from a background local or remote service. The more often you poll the closer you get to the real-time push.
- SMS Android allows you to intercept SMS messages. Your server sends a specially encoded SMS to your phone, whenever there is something new. Your app intercepts all messages, looks for the ones from the server, then pops up a notification.
- Persistent TCP/IP The phone initiates a long-lived mostly idle TCP/IP connection with the server and maintains it by occasionally sending keepalive messages. Whenever there is something new on the server, it sends a messages to the phone over the TCP connection.
这里是两篇我觉得说得很好的网址:
http://tokudu.com/2010/how-to-implement-push-notifications-for-android/
http://blog.csdn.net/joshua_yu/article/details/6563587
当然,我的第一选择也是尝试C2DM,在注册完C2DM服务的账号后,google发的“AC2DM invitation”邮件里有提到仍处在试验中,加上我们要实现的产品需要一个稳定环境,所以尝试至此,也就中途放弃了,有兴趣的可以继续:http://code.google.com/intl/zh-CN/android/c2dm/#intro
之后,我开始尝试使用openfire+smack来自己搭建一个Push platform,用openfire作为Push service,然后借用anroidpn开源工程代码(做了一定的修改),能够做到从Server Push信息到android client。对于这套方案,我并没有做并发测试(这里有提到:http://wenku.baidu.com/view/85cfcd5f312b3169a451a41f.html)以及电量消耗测试,因此只能说,这个可行,也易于实现。
最终我们要选择哪种方式,现在还没有明确的答案,不过也不远了。。