+ All Categories
Home > Documents > Максим Щеглов - Google Cloud Messaging for Android

Максим Щеглов - Google Cloud Messaging for Android

Date post: 10-May-2015
Category:
Upload: ua-mobile
View: 1,009 times
Download: 0 times
Share this document with a friend
Popular Tags:
21
Google Cloud Messaging for Android Shcheglov Maksym MTS1 at Magento inc.
Transcript
Page 1: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Shcheglov MaksymMTS1 at Magento inc.

Page 2: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

GCM & C2DM

• no signup to get access;

• no authentication using Google account;

• no message quota.

Page 3: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Requirements

• Android 2.2 or higher;

• Google account (OS version < Android 4.0.4);

• project ID (using Google API console);

• API key (using Google API console).

Page 4: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Requirements

Page 5: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Requirements

Page 6: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

GCM Server

Mobile phone

Registration ID

1

2

3

Registration ID

Sender ID,Application ID

Enabling GCM

Page 7: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Enabling GCMimport com.google.android.gcm.GCMRegistrar;

public class UAMobileActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

final String regID = GCMRegistrar.getRegistrationId(this);

if (regID.equals("")) {

// register application

GCMRegistrar.register(this, "484449755275");

} else {

// Device is already registered on GCM

}

}

}

Page 8: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Enabling GCMimport com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {

@Override

protected void onRegistered(Context context, String registrationID) {

//send registrationID to the server

registerOnServer(context, registrationID);

}

}

Page 9: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

GCM Server

Mobile phone

1

2

A message with API key,

Registration ID

Sending a message

Page 10: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Sending a messageRequest

https://android.googleapis.com/gcm/send

HTTP headers:

Content-Type:application/json

Authorization:key=AIzaSyAIpOT5VHEOthyrwKjwrNwwEVHQIgioypk

HTTP body:

{

“collapse_key” : “news_update”,

“time_to_live” : 100,

“delay_while_idle” : true,

"data" : { ... },

"registration_ids" : [”ID1”, “ID2”, “ID3”],

}

Page 11: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Sending a messageResponse

{

"multicast_id": 112,

"success": 2,

"failure": 1,

"canonical_ids": 1,

”results": [

{ “message_id": "1:2036" },

{ "message_id": "1:7695", "registration_id": ”102" },

{ "error": "NotRegistered"}

]

}

Page 12: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Sending a messageClient

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {

@Override

protected void onMessage(Context context, Intent intent) {

// received the message

final Bundle bundle = intent.getExtras();

String data = bundle.getString("some_data");

}

}

Page 13: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Unregistration

• manually by sending an intent com.google.android.c2dm.intent.UNREGISTER;

• uninstall the application;

• registration ID is expired;

• application is updated, but does not have a broadcast receiver configured to receive com.google.android.c2dm.intent.RECEIVE intents.

Page 14: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

GCM Server

Mobile phone

1

2

Unregistration

3

invalidate

4

5

Device not registered error

Page 15: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Message states

• sent;

• stored (a device is offline);

• collapsed (a device is offline & we have a new message);

• throttled.

Page 16: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Concepts

• send-to-sync;

• message with payload.

Page 17: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

Features

• no broadcasting;

• no guarantees about delivery and order;

• message multicasting (up to 1000 devices per 1 request);

• multiple senders (max 100 project IDs per application);

• store up to 100 non-collapsible messages;

• maximum 4kb per message;

• optimizations;

• analytics.

Page 18: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

How to migrate from C2DM

Client

• deliver a new version of your app;

• send a flag with registration ID.

Server

• new endpoint;

• API key in the Authorization header.

Page 19: Максим Щеглов - Google Cloud Messaging for Android

Google Cloud Messaging for Android

GCM & APNS

• no certificates;

• one http address for development and production;

• uses json or plaint text in requests, not binary data;

• no feedback service;

• developer-friendly error codes;

• no actions (alert/badge/sound);

• message size (4kb & 256b).

Page 20: Максим Щеглов - Google Cloud Messaging for Android

Demo

Page 21: Максим Щеглов - Google Cloud Messaging for Android

Q & A


Recommended