gcm presentation 2.0 - university of iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... ·...

62
INTRODUCTION Google Cloud Messaging (GCM) 10/30/12

Upload: others

Post on 31-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

INTRODUCTION  Google  Cloud  Messaging  (GCM)  

10/30/12  

Page 2: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Footprint  • A  loca8on  based  socializa8on  App.  • Message  Management  System.  

• Messages  Detec*on  • New  messages.  • New  comments.  

10/30/12  

Page 3: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

PULL  

Footprint  Server   Footprint  APP  on  mobile  device  

H:pResponse  [Messages]    

HDpPost  [Update]  

§  Efficiency  problems  §  Unnecessary  BaDery  usage  §  Unnecessary  data  usage  

   

10/30/12  

Page 4: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Push  

•  The  system  can  • Wake  up  the  App  when  the  message  arrives  •  Store  the  message  in  case  the  device  is  offline.  •  Mul8cas8ng  

Footprint  Server   Footprint  APP  on  mobile  device  

Messages    

10/30/12  

Page 5: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

C2DM  &  GCM  

• A  Google  Service  that  helps  developers  send  data  from  servers  to  their  Android  applica8ons  on  Android  devices.  

• Handle  all  aspects  of  queuing  of  messages  and  delivery  to  the  target  Android  applica8on  running  on  the  target  device.  

C2DM  has  been  officially  deprecated  and  replaced  by  GCM  

10/30/12  

Page 6: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Footprint  Server   Footprint  APP  on  mobile  device  

Google  Server  

Offline  Messages    Messages    

10/30/12  

Page 7: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Advantages  of  GCM  (comparing  with  C2DM)  •  Simple  •  No  client  login  token  •  No  sign  up  form  •  No  quotas  

•  Powerful  • Mul*cas*ng  •  Expiring  messages  • Messages  with  payload  –  4kb  

•  Fast  •  4.7  milliseconds  to  send  a  message  

10/30/12  

Page 8: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

ARCHITECTURAL  OVERVIEW  

10/30/12  

Page 9: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Architectural  Overview  •  Components        The  physical  en88es  that  play  a  role  in  GCM.    •  Creden*als  The  IDs  and  tokens  that  are  used  in  different  stages  of  GCM  to  ensure  that  all  par8es  have  been  authen8cated,  and  that  the  message  is  going  to  the  correct  place.    •  Lifecycle  Flow  The  primary  processes  involved  in  cloud-­‐to-­‐device  messaging.  

10/30/12  

Page 10: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Components  

GCM  Server  

Mobile  Device  

Footprint  Server  

10/30/12  

Page 11: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Credentials  •  Sender  ID    •  Project  ID  instead  of  email  

•  Applica8on  ID    •  Package  name  •  Iden8fy  Android  applica8on  

•  Registra8on  ID    •  Tied  to  a  par8cular  APP  on  device    •  Permission  to  receive  massages  

•  User  Account    •  Not  required  for  Android  4.0.4  or  higher  

•  Sender  Auth  Token    •  An  API  key  instead  of  a  ClientLogin  Auth  token  •  Included  in  the  header  of  POST  requests  

10/30/12  

Page 12: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Lifecycle  Flow  

•  Enabling  GCM.    •  An  Android  applica8on  running  on  a  mobile  device  registers  to  receive  messages.  

•  Sending  a  message.    •  A  3rd-­‐party  applica8on  server  sends  messages  to  the  device.  

•  Receiving  a  message.    •  An  Android  applica8on  receives  a  message  from  a  GCM  server  

10/30/12  

Page 13: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

GCM  –  Registration      •  Ini8ally,  Applica8on  request  to  GCM  server  that  it  wants  to  use  GCM.  In  response,  GCM  assign  a  Reg-­‐id  to  device.  

 

Server   GCM  

Applica8on  

Reg.  Request  

Reg-­‐id  Reg-­‐id  

Reg-­‐id  /  Response  

Response  

10/30/12  

Page 14: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

GCM  -­‐  Unregistration  •  At  first,  our  Server  doesn’t  know  that  Applica8on  has  been  uninstalled.  

Server   GCM  

Applica8on  

Update  /  Response  

Update  /  Response  

Invalidate  this  address  

Update  /  Response  Device  not  registered  

Get  rid  of  Reg-­‐id    from  Database  GCM  Framework  on  device  iden8fies  and  no8fy  GCM  Server  that  

applica8on  has  been  uninstall.    

10/30/12  

Page 15: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Implementation  •  Go  to  Google  APIs  console  page  (hDps://code.google.com/apis/console)  and  create  API  project.   10

/30/12  

Page 16: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Implementation  –  Cont.  

10/30/12  

Page 17: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Library  Installation  •  In  Android  SDK  Manager  ,  Extras  -­‐>  Google  Cloud  Messaging  for  Android.  

10/30/12  

Page 18: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Code  -­‐  Register  •  Applica8on  have  to  send  Intent  to  GCM  Framework  on  device.    

•  GCM  Framework  will  communicate  with  GCM  Server.  

GCM  

Applica8on  

GCM  Framework  

Intent  

10/30/12  

Page 19: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Code  –  Send  Intent  import com.google.android.gcm.GCMRegistrar @Override Protected void onCreate(Buldle savedInstanceState){

if(GCMRegistrar.getRegistrationId(this).equals(“ ”)) { GCMRegistrar.register(this, “98067174480”);    

Project-­‐ID  

10/30/12  

Page 20: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Code  –  Listen  Intent  •  GCM  Server  will  create  Reg-­‐id  for  applica8on  and  returns  to  GCM  Framework  ,  which  will  send  Intent  to  applica8on.  

•  Applica8on  has  to  Listen  this  Intent.  

GCM  

Applica8on  

GCM  Framework  

Reg-­‐id  

Intent  

10/30/12  

Page 21: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Code  –  Listen  Intent  –  cont.  import com.google.android.gcm.GCMBaseIntentService public class GCMIntentService extends

GCMBaseIntentService { @override protected void onRegistered (Context ctx , String regId)

{ sendToAppServer(regId); }

@override protected void onMessage(Context ctx, Intent intent)

{ final Bundle bundle = intent.getExtras(); yourfunction(bundle); }

}

10/30/12  

Page 22: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Permissions    In  Manifest  file  :-­‐        < uses-permission android:name=“com.google.android.c2dm.permission.RECEIVE >

10/30/12  

Page 23: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

•  Able  to  communicate  with  your  client.  •  Able  to  fire  off  HTTPS  requests  to  the  GCM  server.  •  Able  to  handle  requests  and  resend  then  as  needed,  using  exponen8al  back-­‐off.  

•  Able  to  store  the  API  key  and  client  registra8on  IDs.    

Role  of  the  Server  

10/30/12  

Page 24: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Sending  Messages  

Server   Auth  

App  

Reg  ID,  API  Key  

API  Key  

Project  ID  

10/30/12  

Page 25: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

An  Example  JSON  request  

Content-Type:application/json Authorization: key= AIzaSyB- 1uEai2WiUapxCs2Q0GZYzPu7Udno5aA { "registration_ids":"APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."], "data" : { ... }, }

If  Content-­‐Type  is  omi:ed,  the  format  is  assumed  to  be  plain  text  

10/30/12  

Page 26: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Can  we  send  a  single  message  to  multiple  devices?  

Yes!  GCM  supports  message  mul*cas*ng  

10/30/12  

Page 27: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

•  A  3rd-­‐party  applica8on  server  can  either  send  messages  to  a  single  device  or  to  mul8ple  devices.    •  You  have  2  choices  in  how  you  construct  requests  and  responses:  plain  text  or  JSON.  •  A  message  sent  to  mul8ple  devices  simultaneously  is  called  a  mul$cast  message  •  However,  to  send  mul8cast  messages,  you  must  use  JSON.  Plain  text  will  not  work.  

 

Sending  Messages  

10/30/12  

Page 28: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Multicasting  

Server  

App   App   App  

10/30/12  

Page 29: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Example  request  (JSON)  

{ "collapse_key": "score_update", "time_to_live": 108, "delay_while_idle": true, "data": { ... }, "registration_ids":["4","8","15","16","23","42"] }

Up  to  1000  messages  at  a  *me!  

10/30/12  

Page 30: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Sample  Response  (JSON)  { "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"} ] }

10/30/12  

Page 31: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

•  First  message:  success,  not  required.  •  Second  message:  should  be  resent  (to  registra8on  ID  8).  •  Third  message:  had  an  unrecoverable  error  (maybe  the  value  got  corrupted  in  the  database).  •  Fourth  message:  success,  nothing  required.  •  Fi\h  message:  success,  but  the  registra8on  ID  should  be  updated  in  the  server  database  (from  23  to  32).  •  Sixth  message:  registra8on  ID  (42)  should  be  removed  from  the  server  database  because  the  applica8on  was  uninstalled  from  the  device.  

In  this  Example:  

10/30/12  

Page 32: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Can  our  app  receive  message  from  multiple  senders?  

Yes  again!  

10/30/12  

Page 33: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Multiple  Senders  

Server  

App  

10/30/12  

Page 34: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

How  to  do  it?  import com.google.android.gcm.GCMRegistrar; @override protected void onCreate(Bundle savedInstanceState){ GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); if (regId.equals("")) { GCMRegistrar.register(this, "10", "12" ); }

Project  IDs  

10/30/12  

Page 35: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

How  to  do  it?  import com.google.android.gcm.GCMRegistrar; Public class GCMIntentService extends GCMBaseIntentService{ @override protected void onRegistered(Context ctx,String redId){

sendToFootPrint(regId); sendToSocialUpdateServer(redId);

}

Multiple  servers  can  send  message  to  one  application  

Up  to  100  projects!  

One  common  registration  id  

10/30/12  

Page 36: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

What  if  the  message  expires  before  it  is  delivered?  

GCM  supports  TTL  (Time  to  leave)  

10/30/12  

Page 37: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Time  To  Leave  

Server  

App  

TTL   10/30/12  

Page 38: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Example  request  (JSON)  

{ "collapse_key": "score_update", "time_to_live": 108, "delay_while_idle" : true, "data": { ... }, "registration_ids":["4","8","15","16","23","42"] }

10/30/12  

Page 39: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Time  To  Leave  

•  TTL  value  from  0  second  to  4  weeks.  • Messages  with  TTL  value  0  are  not  stored  by  GCM  • Default  TTL  value  is  4  weeks   10

/30/12  

Page 40: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Can  we  send  Instant  Messages  using  GCM?  

GCM  supports  message  with  payload  data  

10/30/12  

Page 41: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

• GCM  supports  messages  contains  payload  data  up  to  4KB  •  The  GCM  service  handles  all  aspects  of  queuing  of  messages  

Messages  with  payload  

10/30/12  

Page 42: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Messages  with  payload  

Server  

App  

10/30/12  

Page 43: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Example  request  (JSON)  

{ "registration_ids":"APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."], "data" : { ... }, }

Messages  with  payload  are  non-­‐collapsible  messages  

10/30/12  

Page 44: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Messages  with  payload  

Server  

App  

10/30/12  

Page 45: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Messages  with  payload  

Server  

App  

4KB  

10/30/12  

Page 46: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Messages  with  payload  

Server  

App  

32KB  

10/30/12  

Page 47: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Messages  with  payload  

Server  

App  

256KB  

10/30/12  

Page 48: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Messages  with  payload  

Server  

App  

512KB  

Stores  up  to  100  messages  if  the  device  is  offline  

10/30/12  

Page 49: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

JSON  message  and  helper  function  { "message_type":"deleted_message", "total_deleted" :"115“, },

import com.google.android.gcm.GCMRegistrar; Public class GCMIntentService extends GCMBaseIntentService{ @override protected void onDeletedMessages (Context ctx,int total){

fullySyncWithServer(total); }

10/30/12  

Page 50: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

GCM  Reliability  &  Optimization  

10/30/12  

Page 51: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

GCM  Reliability  

App  

10/30/12  

Page 52: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

GCM  Reliability  

App  RMQ  

10/30/12  

Page 53: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

• Provide  fresh  data  all  the  8me  • Op8mized  for  baDery  life  

GCM  Optimization  

10/30/12  

Page 54: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

GCM  Optimization  

Server  

App  

Thro:le  Queue  

10/30/12  

Page 55: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Communication  in  our  Project

•  Our  app  is  a  loca8on  based  and  real-­‐8me  socializa8on  applica8on.  

•  Quality:  •  Real-­‐8me  data  update  •  Detect  new  messages  in  movements  •  Energy  saving  

•  Solu8on:  •  Combine  HTTP  and  GCM  together  

 

10/30/12  

Page 56: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Cases: •  Login:  

User

GCM

Server

Upload  current  loca*on

Messages  

10/30/12  

Page 57: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Cases: •  Movement:  

User

GCM

Server

Upload  current  loca*on

Messages  

10/30/12  

Page 58: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Cases: •  Create  a  new  message:  •  Create  a  new  comment:  

User1

GCM

Server Upload  the  message

Calculate  the  receivers

User2 Fetch

Message

10/30/12  

Page 59: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Cases: •  Off-­‐Line  

User1

GCM

Server

10/30/12  

Page 60: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

Energy  Saving

• Use  “Push”  to  reduce  the  frequency  of  asking  server  • Only  moving  and  logging  will  cause  loca8on  update  • Use  the  power  of  server  to  do  the  majority  of  calcula8on

10/30/12  

Page 61: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

References  

•  hDp://developer.android.com/guide/google/gcm/gcm.html  

•  hDps://developers.google.com/android/c2dm/  

•  Google  I/O  2012  -­‐  Google  Cloud  Messaging  for  Android  hDp://www.youtube.com/watch?v=YoaP6hcDctM&feature=plcp    

10/30/12  

Page 62: GCM presentation 2.0 - University of Iowahomepage.divms.uiowa.edu/~ochipara/classes/sensing... · Code–)Listen)Intent)–)cont.) import com.google.android.gcm.GCMBaseIntentService

10/30/12