Android Question GCM Push Notification - Device Registration problems

Discussion in 'Android Questions' started by henrywood, Apr 1, 2015.

  1. henrywood

    henrywood 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(
    SenderId = 
    Then in my Init activity I have

    Sub registerDevice

    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     
    "sender", Main.GCM_PROJECT_ID)
    End If
    Dim r As Reflector
    Dim i2 As Intent
       i2 = r.CreateObject(
    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"""))
    "app", pi)
    End Sub

    Sub HandleRegistrationResult(Intent As Intent)

    If Intent.HasExtra("error"Then
    "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
    "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 = 
    Dim j As HttpJob
    "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 !

  2. Erel

    Erel Administrator Staff Member Licensed User

    There are two different ids:
    1. The device name (Main.Device_id)
    2. The push id.

    GCM service has nothing to do with the first id. It only work with the second id, which is returned from the GCM service in HandleRegistrationResult.

    The first id is in some cases useful for us to map the push id with a more meaningful id.
  3. henrywood

    henrywood Active Member Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice