android push机制-C2DM

http://bigcat.easymorse.com/?p=1210

 

 

 

参考http://code.google.com/intl/zh-CN/android/c2dm/index.html#intro android2.2以上支持,支持第三方应用程序的push。实现令人心动的消息push,GMail就是这么实现的,收信的速度比网页还快。 Components: 1,移动设备:必须运行android,并且安装Market,至少有一个登录的google账号。(Google坑爹啊) 2,自己的服务器:自己的服务器 3,C2DM服务器:google的服务器 授权机制: 1,Sender ID:一个google账号,用于标示开发者的身份,比如[email protected] 2,Application ID:Manifest.xml里面的pacakage name。用于标示应用程序 3,Registration ID:当应用程序向C2DM服务器注册时,C2DM服务器会返回这个ID,当应用程序获得这个ID之后,应该告诉自己的服务器,自己的服务器把这个ID存在数据库里面,用于告诉C2DM服务器标示客户端。 4,Google User Account:要使用C2DM服务,必须有一个google账号,再骂一次,坑爹啊GG。 5,Sender Auth Token:自己的服务器与C2DM服务器通信的认证。 应用程序发送Intent,com.google.android.c2dm.intent.REGISTER,附上自己的SenderID和AppId,就可以向C2DM服务器进行注册,注册成功之后,可以收到REGISTRATION Intent,获得Registration ID,这个Registration ID是会被C2DM改变的,所以这个REGISTRATION Intent可能会收到多次,要记得存储和发送给自己的服务器。 Here is the sequence of events that occurs when the application server sends a message: 1,The application server sends a message to C2DM servers. 2,Google enqueues and stores the message in case the device is inactive. 3,When the device is online, Google sends the message to the device. 4,On the device, the system broadcasts the message to the specified application via Intent broadcast with proper permissions, so that only the targeted application gets the message. This wakes the application up. 5,The application does not need to be running beforehand to receive the message.The application processes the message. If the application is doing non-trivial processing, you may want to grab a wake lock and do any processing in a Service. An application can unregister C2DM if it no longer wants to receive messages. This is the sequence of events that occurs when an Android application running on a mobile device receives a message: 1,The system receives the incoming message and extracts the raw key/value pairs from the message payload. 2,The system passes the key/value pairs to the targeted Android application in a com.google.android.c2dm.intent.RECEIVE Intent as a set of extras. 3,The Android application extracts the raw data from the RECEIVE Intent by key and processes the data.

你可能感兴趣的:(android,应用服务器,Google,mobile,Gmail)