SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
Google Cloud Messaging
      for Android
 Luca Morettoni <luca@morettoni.net>
Google Cloud Messaging
Aggiornare i dati delle APP:
● Polling;
● Notifiche PUSH.

Vantaggi delle notifiche PUSH:
● Minor consumo di risorse (batteria/banda);
● Aggiornamenti (quasi) real-time;
● L'applicazione non deve essere attiva.
Google Cloud Messaging
Limiti/richieste di GCM:
● Android 2.2 o superiore;
● Google Play Store installato;
● L'utente deve avere almeno un profilo
  Google configurato (per versioni < 4.0.4);
● Payload dal server alle app limitato (~4K).
Google Cloud Messaging
Registrazione dei device




                               1

                           2



  3
Google Cloud Messaging
Invio di notifiche

                 1



                 2




                     3
Google Cloud Messaging
Prima di cominciare:
     https://code.google.com/apis/console
                   1.   Prendete nota dell'ID del progetto (nella URL);
                   2.   Attivate il servizio Google Cloud Messaging;
                   3.   Create una nuova chiave per il server.
Google Cloud Messaging
Android side:

1.   Registrare il device sui server GCM;
2.   Ottenere il device ID;
3.   Inviare il device ID al proprio server;
4.   Attendere le notifiche!
Google Cloud Messaging
AndroidManifest.XML

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<permission android:name="net.morettoni.terremoto.permission.C2D_MESSAGE" android:
protectionLevel="signature" />
<uses-permission android:name="net.morettoni.terremoto.permission.C2D_MESSAGE" />
<uses-permission   android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission   android:name="android.permission.INTERNET" />
<uses-permission   android:name="android.permission.GET_ACCOUNTS" />
<uses-permission   android:name="android.permission.WAKE_LOCK" />
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:
permission="com.google.android.c2dm.permission.SEND" >
  <intent filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    <category android:name="net.morettoni.terremoto" />
  </intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
Google Cloud Messaging
Registrazione

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);

final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
  GCMRegistrar.register(this, ID_PROGETTO);
} else {
  // controlliamo se siamo registrati sul nostro server
  if (!GCMRegistrar.isRegisteredOnServer(this))
    ...
  }
}
Google Cloud Messaging
GCMIntentService

public class GCMIntentService extends GCMBaseIntentService {
  protected void onError(Context context, String errorId) {}
  protected void onMessage(Context context, Intent intent) {}
  protected void onRegistered(Context context, String registrationId) {}
  protected void onUnregistered(Context context, String registrationId) {}
}
Google Cloud Messaging
Server side

1. Effettuare un POST al server GCM;
2. Eliminare/aggiornare i device ID.
Google Cloud Messaging
Server side (POST)
https://android.googleapis.com/gcm/send
header:
Authorization: key= CHIAVE_SERVER
Content-Type: application/json



body:
{
    registration_ids: ['device_1', 'device2', ..., 'device1000'],
    collapse_key: 'key',
    data: { 'payload_data': 'ABC123...' }
}
Google Cloud Messaging
Altri campi "interessanti":
"delay_while_idle": true| false

"time_to_live": seconds (default 4 settimane)

"dry_run": true| false
Google Cloud Messaging
Server side (RESPOSE)
{
    "multicast_id": 216,
    "success": 3,
    "failure": 3,
    "canonical_ids": 1,
    "results": [
      { "message_id": "1:0408" },
      { "error": "Unavailable" },
      { "error": "InvalidRegistration" },
      { "message_id": "1:1516" },
      { "message_id": "1:2342", "registration_id": "32" },
      { "error": "NotRegistered"}
    ]
}
Google Cloud Messaging
alcune risorse:

● http://developer.android.com/google/gcm/index.html
● https://groups.google.com/forum/?fromgroups#!
    forum/android-gcm
●   <SDK_ROOT>/extras/google/gcm/samples
●   https://plus.google.com/u/0/100229757360577322667/
    http://bit.ly/morettoni_plus

Weitere ähnliche Inhalte

Ähnlich wie GCM aperitivo Android

GCM Android
GCM AndroidGCM Android
GCM Androidaswapnal
 
Gcm presentation
Gcm presentationGcm presentation
Gcm presentationNiraj Singh
 
Android Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmAndroid Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmJohan Nilsson
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for AndroidRanjitha R_14
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device MessagingFernando Cejas
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messagingFe
 
AC2DM For Security
AC2DM For SecurityAC2DM For Security
AC2DM For SecurityJason Ross
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloudfirenze-gtug
 
Google Cloud Messaging
Google Cloud Messaging Google Cloud Messaging
Google Cloud Messaging Lavakush Verma
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineLars Vogel
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017ketan Bordekar
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingJohan Nilsson
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in androidRIA RUI Society
 
Raspberry pi and Google Cloud
Raspberry pi and Google CloudRaspberry pi and Google Cloud
Raspberry pi and Google CloudFaisal Mehmood
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceAndroid C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceLars Vogel
 

Ähnlich wie GCM aperitivo Android (20)

Magda badita gcm
Magda badita  gcmMagda badita  gcm
Magda badita gcm
 
GCM Android
GCM AndroidGCM Android
GCM Android
 
Gcm presentation
Gcm presentationGcm presentation
Gcm presentation
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
Android Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmAndroid Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG Stockholm
 
GCM for Android
GCM for AndroidGCM for Android
GCM for Android
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for Android
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messaging
 
Workshop: Android
Workshop: AndroidWorkshop: Android
Workshop: Android
 
AC2DM For Security
AC2DM For SecurityAC2DM For Security
AC2DM For Security
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
 
Google Cloud Messaging
Google Cloud Messaging Google Cloud Messaging
Google Cloud Messaging
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App Engine
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device Messaging
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in android
 
A Journey into Google Cloud Messaging
A Journey into Google Cloud MessagingA Journey into Google Cloud Messaging
A Journey into Google Cloud Messaging
 
Raspberry pi and Google Cloud
Raspberry pi and Google CloudRaspberry pi and Google Cloud
Raspberry pi and Google Cloud
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceAndroid C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen Conference
 

Kürzlich hochgeladen

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Kürzlich hochgeladen (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

GCM aperitivo Android

  • 1. Google Cloud Messaging for Android Luca Morettoni <luca@morettoni.net>
  • 2. Google Cloud Messaging Aggiornare i dati delle APP: ● Polling; ● Notifiche PUSH. Vantaggi delle notifiche PUSH: ● Minor consumo di risorse (batteria/banda); ● Aggiornamenti (quasi) real-time; ● L'applicazione non deve essere attiva.
  • 3. Google Cloud Messaging Limiti/richieste di GCM: ● Android 2.2 o superiore; ● Google Play Store installato; ● L'utente deve avere almeno un profilo Google configurato (per versioni < 4.0.4); ● Payload dal server alle app limitato (~4K).
  • 5. Google Cloud Messaging Invio di notifiche 1 2 3
  • 6. Google Cloud Messaging Prima di cominciare: https://code.google.com/apis/console 1. Prendete nota dell'ID del progetto (nella URL); 2. Attivate il servizio Google Cloud Messaging; 3. Create una nuova chiave per il server.
  • 7. Google Cloud Messaging Android side: 1. Registrare il device sui server GCM; 2. Ottenere il device ID; 3. Inviare il device ID al proprio server; 4. Attendere le notifiche!
  • 8. Google Cloud Messaging AndroidManifest.XML <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/> <permission android:name="net.morettoni.terremoto.permission.C2D_MESSAGE" android: protectionLevel="signature" /> <uses-permission android:name="net.morettoni.terremoto.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android: permission="com.google.android.c2dm.permission.SEND" > <intent filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="net.morettoni.terremoto" /> </intent-filter> </receiver> <service android:name=".GCMIntentService" />
  • 9. Google Cloud Messaging Registrazione GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, ID_PROGETTO); } else { // controlliamo se siamo registrati sul nostro server if (!GCMRegistrar.isRegisteredOnServer(this)) ... } }
  • 10. Google Cloud Messaging GCMIntentService public class GCMIntentService extends GCMBaseIntentService { protected void onError(Context context, String errorId) {} protected void onMessage(Context context, Intent intent) {} protected void onRegistered(Context context, String registrationId) {} protected void onUnregistered(Context context, String registrationId) {} }
  • 11. Google Cloud Messaging Server side 1. Effettuare un POST al server GCM; 2. Eliminare/aggiornare i device ID.
  • 12. Google Cloud Messaging Server side (POST) https://android.googleapis.com/gcm/send header: Authorization: key= CHIAVE_SERVER Content-Type: application/json body: { registration_ids: ['device_1', 'device2', ..., 'device1000'], collapse_key: 'key', data: { 'payload_data': 'ABC123...' } }
  • 13. Google Cloud Messaging Altri campi "interessanti": "delay_while_idle": true| false "time_to_live": seconds (default 4 settimane) "dry_run": true| false
  • 14. Google Cloud Messaging Server side (RESPOSE) { "multicast_id": 216, "success": 3, "failure": 3, "canonical_ids": 1, "results": [ { "message_id": "1:0408" }, { "error": "Unavailable" }, { "error": "InvalidRegistration" }, { "message_id": "1:1516" }, { "message_id": "1:2342", "registration_id": "32" }, { "error": "NotRegistered"} ] }
  • 15. Google Cloud Messaging alcune risorse: ● http://developer.android.com/google/gcm/index.html ● https://groups.google.com/forum/?fromgroups#! forum/android-gcm ● <SDK_ROOT>/extras/google/gcm/samples ● https://plus.google.com/u/0/100229757360577322667/ http://bit.ly/morettoni_plus