Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

GCM - Parte 2

  • Login to see the comments

  • Be the first to like this

GCM - Parte 2

  1. 1. Google Cloud Messaging for Android - Parte II
  2. 2. Recordar Arquitectura:Ejemplo - Chrome to Phone
  3. 3. Envío de mensajes desde el servidora GCMPetición POST https://android.googleapis.com/gcm/sendHeader: ● Authorization(key) ● Content-Type (json o texto plano)Body: ● registration_ids ● collapse_key (opcional) ● data ● delay_while_idle ● time_to_live
  4. 4. Ejemplo de petición json{ "collapse_key": "score_update", "time_to_live": 108, "delay_while_idle": true, "data": { "score": "4x8", "time": "15:16.2342" }, "registration_ids":["4", "8", "15", "16", "23", "42"]}
  5. 5. Android Manifest (permisos)● com.google.android.c2dm.permission.RECEIVE● android.permission.INTERNET● android.permission.GET_ACCOUNTS (SDK < 4.0.4)● android.permission.WAKE_LOCK● applicationPackage + ".permission.C2D_MESSAGE". Por ejemolo com.example.app.permission.C2D_MESSAGE
  6. 6. Recibir los datos● Crear un intent service (clase que extiende de IntentService)● Iniciar el servicio context.startService(intent);● En la llamada al callback onHandleIntent, recuperar los datos enviados@Override public final void onHandleIntent (Intent intent) { // TODO: do stuff}Por ejemploString score = intent.getExtra("score");String time = intent.getExtra("time");
  7. 7. Graciashttp://developer.android.com/google/gcm/gcm.html

×