0

我需要獲取GCM推送通知實施的註冊ID嗎?由於我使用的是GoogleCloudMessaging類,但沒有獲得ID。如何獲取Google Cloud Messenger的註冊ID

+0

這裏有一個例子,以獲得registrationId http://developer.android.com /google/gcm/client.html#sample-register – josuadas

+0

您是否已從開發者控制檯激活GCM服務? –

+0

不,如何做? –

回答

0

使用GoogleCloudMessaging類和發送您從google開發人員Api控制檯獲得的senderId的註冊函數。

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); 
String regid = gcm.register(senderId); 
+0

現在,這已被棄用,請使用intent並在其中調用instanceID.getToken()。 –

0

現在怎麼做到這一點可以在https://developers.google.com/cloud-messaging/android/client

找到它歸結爲創建一個RegistrationIntentService並使用該接收的令牌。對於刷新令牌創建一個InstanceIDListenerService,並在那裏進行檢索,並首次啓動RegistrationIntentService如下:

Intent regIntent = new Intent(this, myRegistrationIntentService.class); 
startService(regIntent); 
相關問題