Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Wake up your Android with Google Cloud Messaging

Wake up your Android with Google Cloud Messaging

The number of mobile clients that use web applications is growing quickly and end-users require even more real time interaction. Android platform is able to achieve this requirement thanks to Google Cloud Messaging, a service which is able to "wake up" Android clients when your backend requires it.

All users activity or their interaction with others will become the first part of an elegant and efficient notification system for all your Android clients without any useless battery drain.

Emanuele Palazzetti

November 16, 2013
Tweet

More Decks by Emanuele Palazzetti

Other Decks in Technology

Transcript

  1. It’s not easy to organize a conference • find speakers

    • event marketing • prepare website, flyer, etc… • communicate with attendees: ◦ before ◦ during ◦ after The problem
  2. DevFest Android app (use case) • all italian DevFest list

    during the year • for each DevFest provide talks scheduling • some notifications Android app
  3. DevFest Android app (end-user requirements) • notifications without any running

    application • notifications across all owned devices • real time notifications (delay, rooms swap, etc...) • hey! don’t exhaust my battery! Android app
  4. Google Cloud Messaging If you have an Android application and

    a server you should use it! You can finally throw out the “refresh button” Even with your third-party application server Google Cloud Messaging
  5. Google Cloud Messaging • Integrated with Google Play Services •

    Available back to Froyo (remember about dropped support) NOTE: old GCM standalone implementation is deprecated! Use the GoogleCloudMessaging API instead! Google Cloud Messaging
  6. Pros • No battery consumption (server push) • App doesn’t

    need to be running to receive messages • Reduces update latency • Transmit messages to multiple devices Google Cloud Messaging
  7. What happen if user devices are offline? • Google provides

    automatic queue management • When device come back online again, all messages are delivered • We can have 100 stored messages (in the queue) and if you reach that limit, all messages are discarded and a special message is delivered NOTE: use the special message to manage a full sync! Google Cloud Messaging
  8. Application server requirements: • Able to communicate with your client

    (endpoints) • Able to store the API key and client registration IDs • Able to fire off properly formatted requests to the GCM server • Able to generate message IDs to identify each message it sends Application server
  9. Requests to GCM server • You can use two different

    protocols: HTTP or CCS (XMPP) • JSON message: ◦ HTTP: sent as HTTP POST ◦ CCS: message is encapsulated in XMPP message Application server
  10. Android client Some best practices before continue • If you

    are using Play Services SDK, always perform a compatibility check in Activity onCreate() and onResume() • Write your own wrapper around these methods:
  11. Android client About storing your registrationId: • It’s better to

    generate a new one if you update your application • If you use Google Backup Service, avoid to backup registrationId
  12. Android client Done! Remember: • Register your Google API_KEY •

    Configure AndroidManifest.xml • Android registration on GCM • Send received registrationId to your application server (and store it) • Prepare your broadcast receiver • Start sending GCM messages from your server!