cloud messaging in android
TRANSCRIPT
Cloud Messaging in Android
Francesco NerieriEngineering Manager
Android Cloud To Device Messaging
2
NewsServer
C2DM
NewsApp
#1#2
Android Cloud To Device Messaging
3
NewsApp
NewsServer
C2DM#3
Android Cloud To Device Messaging
4
Google AccountClient Login Token
Sign u
p for
m
Activation EmailInitial Quota
Request More Quota
PowerfulFreeSimpleNo Client Login TokenNo Sign Up FormNo QuotaSimplePowerfulMessage MulticastingFastExpiring Messages 95ms Global Average LatencyMessages With PayloadFast4.7 milliseconds
5
6
FootballApp
GCM - Registration
7
GCM
RegID
RegID
RegID
Football Server
FootballApp
Football Server
GCM - Unregistration
8
GCM
9
Auth
Football Application
GCM Framework
10
GCM
Register
11
import com.google.android.gcm.GCMRegistrar;
@Overrideprotected void onCreate(Bundle savedInstanceState) { GCMRegistrar.register(this, “968350041068”);
Android
12
import com.google.android.gcm.GCMRegistrar;
@Overrideprotected void onCreate(Bundle savedInstanceState) { if (GCMRegistrar.getRegistrationId(this).equals(“”)) { GCMRegistrar.register(this, “968350041068”); }
Android
Receive data
13
GCM
Football Application
GCM Framework
RegID
14
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
@Overrideprotected void onRegistered(Context ctx, String regId) { sendToFootballServer(regId);
Android
15
Android
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
@Overrideprotected void onMessage(Context ctx, Intent intent) { final Bundle bundle = intent.getExtras(); doSomeMagic(bundle);
Declare permissions
16
17
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
Android
Football application
18
Register with GCM
Receive real time updates!
Declare permissions
Server
19
GCM Auth
RegID, API Key RegID, API KeyAPI Key
Project ID
FootballApp
Football Server
20
JSON
Content-Type:application/jsonAuthorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{ “registration_ids” : [“APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...”], “data” : { “Team” : “Portugal”, “Score” : “3”, “Player” : “Varela”, },}
3
21
Portugal vs Denmark
Pepe 24Postiga 36
Bendtner 41Bendtner 80
2 2:
GOAL!!!Varela 87
USA
22
Born: May 2, 1975 Leytonstone
Height: 6' 0" (1.83 m)
Team: LA Galaxy
David BeckhamNews
FootballApp
DEVICE C
FootballApp
DEVICE B
FootballApp
DEVICE A
Message Multicasting
23
GCMFootball Server
24
JSON
{ “collapse_key” : “Beckham-News”, “data” : { “Team” : “LA Galaxy”, “Player” : “David Beckham”, } “registration_ids”:[ “APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...”, “APQ23XFer5MtP0retKMfe1KSFWaFUH-1EWab...”, ]},
25
JSON
{ “multicast_id” : “5814378600346514436”, "success":1, "failure":1, "results":[ { "message_id":"0:1337639984251701%921c249af9fd7ecd", }, { "error":"DeviceNotRegistered", } ],}
Message Multicasting
26
One Request Many Devices
Up to 1000 devices simultaneously
USA1
27
David Beckham
David Beckham lifts Stanley Cup
USA 1
David Beckham
David Beckham lifts Stanley Cup
Born: May 2, 1975 Leytonstone
Height: 6' 0" (1.83 m)
Team: LA GalaxyBorn: May 2, 1975 Leytonstone
Height: 6' 0" (1.83 m)
Team: LA Galaxy
NewsNews
USA
Born: May 2, 1975 Leytonstone
Height: 6' 0" (1.83 m)
Team: LA Galaxy
David BeckhamNews
28
FootballApp
Multiple Senders
29
GCMFootball Server
Social UpdatesServer
30
import com.google.android.gcm.GCMRegistrar;
@Overrideprotected void onCreate(Bundle savedInstanceState) { if (GCMRegistrar.getRegistrationId(this).equals(“”)) { GCMRegistrar.register(this, “968350041068”, “652183961211”); }
Android
31
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
@Overrideprotected void onRegistered(Context ctx, String regId) { sendToFootballServer(regId); sendToSocialUpdatesServer(regId);
Android
Multiple Senders
32
One common RegistrationID
Multiple parties can sendmessages to one application
Up to 100 project IDs
USA
Born: May 2, 1975 Leytonstone
Height: 6' 0" (1.83 m)
Team: LA Galaxy
David BeckhamNews
33
1
David Beckham lifts Stanley Cup
Me with the (pretty big) Stanley...
34
San Francisco
25% OFF
KICK OFF!
FootballApp
Time To Live
35
GCM
123
Football Server
36
JSON
{ “collapse_key” : “Food-Promo”, “time_to_live” : 3600, “delay_while_idle” : “true”, “data” : { “Category” : “FOOD”, } “registration_ids”: [“APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...”],},
Time To Live
37
From 0 seconds to 4 weeks
Messages with TTL value of 0are not stored on GCM
Default TTL time is 4 weeks
38
VS
2 2:
Match Chat
Mario says: great match!!!
Herculez says: I agree!!
Cristiano says: Go Portugal!
FootballApp
Messages with Payload
39
GCMFootball Server
40
JSON
{ “registration_ids” : [ “APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...”], “data” : { “Nick” : “Mario”, “Text” : “great match!”, “Room” : “PortugalVSDenmark”, },}
128k256k512k
Messages with Payload
41
GCM
4k8k16k32k
FootballApp
Football Server
42
{ “message_type” : “deleted_messages”, “total_deleted” : “115”,},
Android
43
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
@Overrideprotected void onDeletedMessages(Context ctx, int total) { fullSyncWithFootballServer(total);}
Android
Messages with Payload
44
Payload up to 4K per message
Up to 100 messages are stored by GCM
Message to trigger sync after that
Summary
45
Message Multicasting for News
Time To Live for Events and Promos
Multiple Senders for Social Updates
Messages with Payload for IM
3
46
Portugal vs Denmark
Pepe 24Postiga 36
Bendtner 41Bendtner 80
2:
Varela 87
47
JSON
{ “collapse_key” : “PortugalDenmark”, “time_to_live” : 4400, “data” : { “Team” : “Portugal”, “Score” : “3”, } “registration_ids”:[ “APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...”, “APQ23XFer5MtP0retKMfe1KSFWaFUH-1EWab...”, ]},
FootballApp
GCM - Reliability
48
GCM
Optimized for battery life
Provide fresh data all the time
GCM Optimization
49
GCM Optimization
50
GCM
Social UpdatesServer
Throttlequeue
Football Server
FootballApp
GCM Optimization
51
GCM
Throttlequeue
Football Server
FootballApp
Throttled 54.6%41.6%
2.6%
1.2%
52
GCM Messages Metrics
Sent
Stored
Collapsed
53
Sample C2DM App
54
Sample C2DM App
55
Sample C2DM App
56
Sample C2DM App
57
Sample C2DM App
58
Sample C2DM App
59
Sample C2DM App
C2DM to GCM Migration
60
C2DM sign ups and quota requestsare now closed!
C2DM servers will keep running!
GCM is now LIVE!
C2DM to GCM Migration
61
Enable GCM
Point your server to:http://android.googleapis.com/gcm/send
New Client App version with projectIdas authorized sender
GCM Documentation
62
Getting started guide with astep by step tutorial
Demo application (client and server)
Getting started for experiencedC2DM developers
GCM Advanced topics
http://developer.android.com
63
?developer.android.com