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

Android notifications with Google Cloud Messaging

Android notifications with Google Cloud Messaging

Introduction to Google Cloud Messaging. The workshop uses Android Mobile Backend Starter with an AppEngine backend.

Emanuele Palazzetti

July 19, 2013
Tweet

More Decks by Emanuele Palazzetti

Other Decks in Programming

Transcript

  1. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google Developer Group
  2. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Who am I? Emanuele Palazzetti  @palazzem  evonove.it/authors/palazzem  github.com/emanuele-palazzetti
  3. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Google Developer Group - Perugia  @GDGPerugia  perugia.gtugs.org  [email protected]
  4. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia What is Google Cloud Messaging
  5. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia A simple use case: I want to chat with my friends
  6. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia How will you resolve these problems? Store messages Send messages from A to B Receive messages
  7. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Traditional pull? Bad idea...too much high battery consumption
  8. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Message push Request for a given transaction is initiated by a central server Clients need to register themselves to a publisher Clients are in idle state
  9. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia GCM is available for two platforms Android Google Chrome (extensions)
  10. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia GCM features Is a free Google service (no quotas) Helps developer send data from servers to their Android applications and upstream messages from user's device back to the cloud Abstraction of all queuing problems Android applications don't need to be up and running to receive messages
  11. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia More technical details Requires Android > 2.2 (Froyo) Google Play Store must be installed Integration with Google Play Services It's not required for you to deploy your app on Google Play Store Google account is required if Android < 4.0.4
  12. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Enable GCM Access to your API console and enable GCM for your app
  13. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Register your app GCM doesn't provide anything else than a simple raw communication protocol You must provide an initial registration step (only the first time) You must have a receiving handler on your client You must have a sending handler on your server
  14. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Don't worry All API are really easy
  15. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia GCM message Lightweight message (max 4kb payload) It can be just an alert to our app (send-to-sync) It can contains some data on the payload (message with payload)
  16. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Message with payload { "registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...", "data" : { "Nick" : "Mario", "Text" : "great match!", "Room" : "PortugalVSDenmark", }, ... }
  17. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Suppose: Users of my application have more than one device I want to trigger a message push to all user's devices I don't want to query and find all device IDs
  18. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Seamless multi-device messaging Map a single user to a notification_key, which you can then use to send a single message to multiple devices owned by the user
  19. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Very advanced feature 1. When new contents are available on our server, we ask to GCM server to send a push message to all user's devices 2. The GCM server checks all registered devices to find the last one in active state 3. It will send the push message 4. It compare the position of this device with other user's devices and if they are too far away, the message is not delivered now
  20. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Other features Persistent connections Upstream messaging Synced notifications across devices
  21. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Be ready! http://evo9.it/www.tofu.st/c http://evo9.it/bradabrams.com/a
  22. Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google

    Developer Group Perugia Emanuele Palazzetti :: Google Developer Group  @palazzem  evonove.it/authors/palazzem  github.com/emanuele-palazzetti/AndroidHappyChat