Android Question GCM Push Notification - Device Registration problems


Active Member
Licensed User
Hi !

I am writing an app that needs to register the DEVICE ID on my servers, so that messages can be sent using this ID as recipient.

Having looked over the forum, I

In my Main Activity I have

Dim objPhone As Phone
DEVICE_ID = objPhone.GetSettings("android_id")
SenderId = "xxxx"
Then in my Init activity I have

Sub registerDevice

   CallSubDelayed2(PushService, "RegisterDevice", False)
End Sub
In my PushService, I have:

Sub Service_Start (StartingIntent As Intent)
   Select StartingIntent.Action
     Case ""
     Case ""
   End Select
End Sub

Sub RegisterDevice (Unregister As Boolean)
   Dim i As Intent
   If Unregister Then     
     i.Initialize("", "")
     i.Initialize("", "")
     i.PutExtra("sender", Main.GCM_PROJECT_ID)
   End If
   Dim r As Reflector
   Dim i2 As Intent
   i2 = r.CreateObject("android.content.Intent")
   Dim pi As Object
   pi = r.RunStaticMethod("", "getBroadcast", _
     Array As Object(r.GetContext, 0, i2, 0), _
     Array As String("android.content.Context", "", "android.content.Intent", ""))
   i.PutExtra("app", pi)
End Sub

Sub HandleRegistrationResult(Intent As Intent)

   If Intent.HasExtra("error") Then
     Utils.Log_("Error: " & Intent.GetExtra("error"))
     ToastMessageShow("Error: " & Intent.GetExtra("error"), True)
   Else If Intent.HasExtra("unregistered") Then
     ' Here we unregister the DEVICE_ID at our own servers
     Dim j As HttpJob
     j.Initialize("UnregisterTask", Me)
     Dim paramsStr As String = "deviceID="&Main.DEVICE_ID&"&uuid="&Main.CURRENTUSER.ID&"&apptype=ANDROID&app="&Main.APP_APPLICATION_NAME.Replace("%s", "")
     j.PostString(Callbacks.CB_DEVICE_UNREGISTRATION_URL, paramsStr)

   Else If Intent.HasExtra("registration_id") Then
     Dim rid As String
     rid = Intent.GetExtra("registration_id")
     Dim j As HttpJob
     j.Initialize("RegisterTask", Me)

     ' Here we register the DEVICE_ID at our own servers
     Dim paramsStr As String = "deviceID="&rid&"&uuid="&Main.CURRENTUSER.ID&"&apptype=ANDROID&app="&Main.APP_APPLICATION_NAME.Replace("&s", "")     
     j.PostString(Callbacks.CB_DEVICE_REGISTRATION_URL, paramsStr)

   End If
End Sub
Sub JobDone(Job As HttpJob)


End Sub
What I fail to understand is, since the RegisterDevice() does not set the registration_id as an extra for the intent started (to Main.DEVICE_ID), how does GCM/Google know the registration ID ???
So in RegisterDevice() do I need to set the registration_id to Main.DEVICE_ID in some extra for the intent ?

Please help me understand !

Thanks !