Google Developer Group Perugia DevFest Central Rome

Size: px
Start display at page:

Download "Google Developer Group Perugia 16.11.2013 DevFest Central Italy @ Rome"


1 Google Developer Group Perugia DevFest Central Rome

2 Who am I? +EmanuelePalazzetti Manager Google Developer Group

3 Wake up your Android with Google Cloud Messaging

4 Google Cloud Messaging Google Cloud Messaging? Not yet...let s talk about something else

5 Conference organization!

6 The problem It s not easy to organize a conference find speakers event marketing prepare website, flyer, etc communicate with attendees: before during after

7 What? Hey! This is a DevFest! We should talk about code!

8 Android app DevFest Android app (use case) all italian DevFest list during the year for each DevFest provide talks scheduling some notifications

9 Android app 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!

10 Google Cloud Messaging 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

11 Google Cloud Messaging 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!

12 Google Cloud Messaging Pros No battery consumption (server push) App doesn t need to be running to receive messages Reduces update latency Transmit messages to multiple devices

13 Registration Device Registration Google Cloud Messaging

14 Registration Registration ID Google Cloud Messaging

15 Registration Google Cloud Messaging Registration ID Your server

16 Send a message Message Google Cloud Messaging Message to: registrationid Your server

17 Google Cloud Messaging 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!

18 Getting started

19 Application server 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

20 Application server 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

21 Send-to-sync message Send-to-sync message with collapse key

22 Message with payload max 4kb payload useful to avoid further connections!

23 Android client Android manifest

24 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:

25 Android client Request registrationid

26 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

27 Android client Simple BroadcastReceiver to manager GCM messages

28 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!

29 Hands on code!

30 +EmanuelePalazzetti Manager Google Developer Group Thanks for your attention!

31 Questions?