Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google Developer Group Perugia Do you know what GDG is?

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google Developer Group Perugia GCM lifecycle

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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)

Slide 22

Slide 22 text

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", }, ... }

Slide 23

Slide 23 text

Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google Developer Group Perugia Some advanced features

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google Developer Group Perugia Nice!

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Android notifications with Google Cloud Messaging Emanuele Palazzetti :: Google Developer Group Perugia Workshop time!

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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