android push notifications 

WITH phonegap

 

Presenter: Holly Schinsky

Blog:  http://devgirl.org

Twitter: @devgirlfl

google cloud messaging (GCM)

  • Push Notification service for Android (similar to APNS for iOS)

  • GCM handles queueing and sending of messages for you

  • Messages can contain up to 4KB of data

  • Use Google's API Console to create a project for use with this service - https://code.google.com/apis/console/

  • Enable the Google Cloud Messaging Service in the console: 

GOOGLE CLOUD MESSAGING (GCM)  cont...

  • Each project is assigned a project number in the URL upon 
creation to identify the sender. For example:   https://code.google.com/apis/console/#project:481516234

  • Project number is required upon registration from your 
application:                                               pushNotification.register(successHandler, errorHandler, {"senderID": "4815162342" ,"ecb":"onNotificationGCM"});  

  • An API Key is also needed from the Google API console project for sending a notification from 3rd party server.

WORKFLOW

 
  • Register app with a call to the GCM Service via PushPlugin.
  • Registration ID is returned and app stores on 3rd party server for use when message needs to be sent.
  • 3rd party server sends a message through GCM Service using an API key and registration ID (or arrary of IDs).

registration id

  • Unique to application + device combo.
  • May expire. 

Registration ID Handling
  • Google recommends handling multiple possible com.google.android.c2dm.intent.REGISTRATION intents when designing your app. 
  • Register the id on the 3rd party server when the application is updated and when backed up and restored.
  • If registration_id is found in the extra of the REGISTRATION intent, the application should also register it again on the server. 

Links

  • Google API Console - https://code.google.com/apis/console/

  • PushPlugin - https://github.com/phonegap-build/PushPlugin

  • node-gcm - Node library for sending messages through the GCM service - https://github.com/ToothlessGear/node-gcm

  • GCM Developer Documentation - http://developer.android.com/google/gcm/gs.html
Made with Slides.com