2013年1月20日 星期日

Google C2DM

 

一. 名詞解釋

Credentials
Sender ID    (SID)開發者的email帳號,用來註冊C2DM service 使用
Application ID使用C2DM 的應用程序名稱,用來確保收到的push message 可以綁訂到正確的程序上
Registration ID (Auth)用C2DM 認可的device去註冊C2DM service後,所得到的一組id,其他第三方伺服器可以透過這一組registration ID去發送訊息,這個id大概每隔一週就會被Renew,鑰重新申請產生
Google User AccountDevice需要透過此google account去通過認證
Sender Auth Token由Sender Id對應的Token,可以得到使用C2DM service

 

 
二.流程說明
1. Enabling C2DM
  1. Server端:啟用註冊程序,可以透過如下的curl command以得到 Authentication id                              #curl -X POST https://www.google.com/accounts/ClientLogin -d Email='wfbss.c2dm@gmail.com' -d Passwd='asd12#$56' -d accountType=HOSTED_OR_GOOGLE -d service=ac2dm -d source=TM-WFBSS-5
  2. Client端:需要在被認可的device上面,啟動C2DM 服務,方可以拿到 registration id,目前側試過,Emulator或 使用Android x86 的vm都可以使用
  3.  第三方首先要先啟動一個registration Intent到C2DM的SERVER (com.google.android.c2dm.intent.REGISTER),且這Intent必須但兩個參數,第一個是SENDER ID,第二個是application ID參數說明請看這。
  4. 如果這個registration成功了,C2DM的Server會回傳(broadcast)一個registration ID,這時候Android applicaiton要把這registration ID先存起來,待會用。(Google可能會一段時間就去refresh這個registration ID)
  5. 完成註冊以及取得resgistration ID以後,Android App必須把此ID傳到自己的server上去。Server一樣得把這ID存起來。

註:register ID會存活直到你unregister,或者直到Google refresh為止。

 



2. Sending a message
  1. 在send a message之前,必須確認Android appSever上已經有 resgistration  ID了,以及Sever必須有ClientLogin authorization token. 至於怎麼取得這個token,可以去看Google官網說明
  2. 完成上面的以後,首先,Sever必須先send訊息至C2DM Sever上
  3. Google收到以後,會先存起來,以免Android device是inactive的狀態。
  4. 當Device是online的狀態,Google就會send訊息至device上。
 



3. Receiving a Message
  1. 首先Android OS會先收到這則Message,
  2. 接著Android OS會把這則訊息,會根據package name發送到含有註冊com.google.android.c2dm.intent.RECEIVE的app上去
  3. 最後,該app就會從自己註冊的RECEIVER的Intent裡收到message,就可以處理資料了。

沒有留言:

How to restore a deleted onenote page

復原不小心誤刪的onenote