android & internet of things with google cloud messaging and appengine - orlando and pulcini
DESCRIPTION
Slides from Antonino Orlando and Simone Pulcini talk @ codemotion roma 2014TRANSCRIPT
![Page 1: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/1.jpg)
ROME 11-12 april 2014ROME 11-12 april 2014
Android & Internet of Things with Google Cloud Messaging and AppEngine
GDG Roma L-AB
Antonino Orlando Simone Pulcini e il GDG Roma L-AB
![Page 2: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/2.jpg)
ROME 11-12 april 2014
Chi siamo: GDG Roma L-AB
http://goo.gl/QG40Os http://goo.gl/6QRlP9
http://goo.gl/cEF2Yn
Il nostro prossimo evento:
![Page 3: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/3.jpg)
ROME 11-12 april 2014
• [email protected]• http://it.linkedin.com/in/orlan
doantonino• https://plus.google.com/+Anto
ninoOrlando
Chi siamo: Antonino Orlando
![Page 4: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/4.jpg)
ROME 11-12 april 2014
• [email protected]• http://www.linkedin.com/i
n/simonepulcini• https://plus.google.com/+Si
monePulcini
Chi siamo: Simone Pulcini
![Page 5: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/5.jpg)
ROME 11-12 april 2014
NFC• RFID (Radio Frequency Identification)• permette una comunicazione bidirezionale:
entro un raggio di 4 cm• opera alla frequenza di 13,56 MHz e può
raggiungere una velocità di trasmissione massima di 424 kbit/s.
![Page 6: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/6.jpg)
ROME 11-12 april 2014
Google Cloud Messaging
1) Invio un messaggio a gcm
2) GCM inoltre al device
![Page 7: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/7.jpg)
ROME 11-12 april 2014
Workflow del lab
1) Il dispositivo rileva un tag
2) il dispositivo notifica l'evento al nostro backend
3) il backend chiede l'invio della notifica a GCM
4) GCM inoltra la notificaall'utente
![Page 8: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/8.jpg)
ROME 11-12 april 2014
Stack software e sorgenti
• ADT Bundle più Plug-in Eclipse per GAE• Google Play Services (da Android SDK Extras)• Android Support Library (da Android SDK
Extras)• github.com/orlando-antonino/GdGLAb_IoT-
AppEngine_TODO.git• github.com/orlando-antonino/SendByNFC.git• github.com/spulci/codemotion2014/tree/master/
CodemotionIOTLabBackend
![Page 9: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/9.jpg)
ROME 11-12 april 2014
• All'interno del progetto possiamo trovare i passi di sviluppo usando la view “tasks” di eclipse
• Abbiamo un tempo definito per eseguire ogni “todo”
• siamo qui per sviluppare insieme... fate domande
Lab How-to
![Page 10: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/10.jpg)
ROME 11-12 april 2014
• Richiamiamo il metodo all'interno dell'activity per richiedere un registrationID al server GCM
• http://developer.android.com/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html
Step 1: registration ID
![Page 11: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/11.jpg)
ROME 11-12 april 2014
• Inseriamo nelle S.P.:1. property_reg_id2. property_app_version• recuperiamo dalle S.P. il
registrationID memorizzato precedentemente:
1. property_reg_id
http://developer.android.com/reference/android/content/SharedPreferences.html
Step 2: Shared Preferences
![Page 12: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/12.jpg)
ROME 11-12 april 2014
• inseriamo il codice necessario a richiedere il registrationID al GCM server
• richiamiamo il metodo all'interno dell'activity per memorizzare localmente il registrationID
• inviamo il registrationID al backend AppEngine
http://developer.android.com/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html
Step 3: GCM
![Page 13: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/13.jpg)
ROME 11-12 april 2014
• Entity: lightweight persistence domain object
• Annotazioni JPA usate: @Entity, @Id, @GeneratedValue
• https://developers.google.com/appengine/docs/java/datastore/jpa/overview-dn2?hl=it
Step 4: creazione di un Entity Bean
![Page 14: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/14.jpg)
ROME 11-12 april 2014
• Pattern DAO• Diversi servizi già realizzati• Il servizio da realizzare rende
persistente un ClientBean• https://
developers.google.com/appengine/docs/java/datastore/jpa/overview-dn2?hl=it
Step 5: servizio addClientBean
![Page 15: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/15.jpg)
ROME 11-12 april 2014
• Esponiamo un servizio sul web in modo da poterlo chiamare da remoto (dal client android)
• Annotazioni: @Api, @ApiMethod (con attributi)
• https://developers.google.com/appengine/docs/java/endpoints/
Step 6: creazione Cloud Endpoint
![Page 16: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/16.jpg)
ROME 11-12 april 2014
• Radice progetto (tasto destro): Google -> Generate Cloud Endpoint Client Library
• Innestiamo il codice nel client Android sistemando i jar generati e chiamando le API (lo abbiamo fatto noi per voi)
Step 7: generiamo e integriamo… (1/2)
![Page 17: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/17.jpg)
ROME 11-12 april 2014
Step 7: generiamo e integriamo… (2/2)• riempiamo la segnatura remota per l'operazione
addclient che prende un ClientBean popolato dal suo registrationId e lo memorizza sul datastore invocando il metodo remoto
• lanciamo l'operazione remota di cui abbiamo preparato la segnatura di cui sopra: viene aperta una connessione HTTP e viene effettuata la chiamata
![Page 18: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/18.jpg)
ROME 11-12 april 2014
E per finire….GCM server side• GCM può essere interrogato via HTTP o XMPP• Lato server in HTTP abbiamo usato
l’implementazione del progetto http://code.google.com/p/gcm/source/browse/#git%2Fgcm-server
• I formati della message request e altra documentazione: https://developer.android.com/google/gcm/http.html
![Page 19: Android & Internet of things with Google Cloud Messaging and AppEngine - Orlando and Pulcini](https://reader037.vdocuments.mx/reader037/viewer/2022103016/5551462bb4c905f2288b4d14/html5/thumbnails/19.jpg)
ROME 11-12 april 2014
GRAZIE A TUTTI!