由於問題說如何找出registration ID在GoogleCloudMessaging API中何時失效? 我已經閱讀了有關類似主題的幾個問題的答案:Do GCM registration id's expire?和Google Coud Mesaging (GCM) and registration_id expiry, how will I know?。這些問題的問題是,這裏的答案是C2DM
或舊的GCM API,它使用GCMRegistrar代替GoogleCloudMessaging API。前兩種方法已折舊。在GoogleCloudMessaging API中,如何處理註冊ID的更新或過期?
我會試着打破我的困惑/問題逐步:
1)在標題Enable GCM,在第二點,它說:
Google may periodically refresh the registration ID, so you should design your Android application with the understanding that the com.google.android.c2dm.intent.REGISTRATION intent may be called multiple times. Your Android application needs to be able to respond accordingly.
The registration ID lasts until the Android application explicitly unregisters itself, or until Google refreshes the registration ID for your Android application. Whenever the application receives a com.google.android.c2dm.intent.REGISTRATION intent with a registration_id extra, it should save the ID for future use, pass it to the 3rd-party server to complete the registration, and keep track of whether the server completed the registration. If the server fails to complete the registration, it should try again or unregister from GCM.
2)現在,如果是這種情況我應該處理BroadcastReceiver中的意圖,並再次發送register()請求以獲取新的註冊ID。但問題是,在標題ERROR_MAIN_THREAD下的同一頁上,它說: GCM methods are blocking. You should not run them in the main thread or in broadcast receivers
。
3)我也明白,還有其他兩種情況時的註冊ID的變化(品目Keeping the Registration State in Sync)根據下高級主題提到: 應用程序更新和備份&恢復。我已經在打開應用程序時處理它們。
4)在GCMRegistrar API,內部GCMBaseIntentService,過去有一個回調onRegistered()方法中,當設備註冊得到其中得到調用。在這裏我曾經堅持註冊ID併發送到第三方服務器。
但是,現在我應該如何處理註冊ID的更新或更新,堅持並將其發送到第三方服務器?
可能是因爲閱讀所有內容而感到困惑,或者我錯過了某些東西。我會非常感謝你的幫助。
更新
即使在Handling registration ID changes in Google Cloud Messaging on Android線程,不存在如何通過谷歌處理ID的週期性刷新提?
此可能的重複 - http://stackoverflow.com/questions/16838654/handling-registration-id-changes-in-google-cloud-messaging-on-android/16839326#16839326 – Eran