Google Cloud Messaging forAndroidShcheglov MaksymMTS1 at Magento inc.
Google Cloud Messaging for Android     GCM & C2DM• no signup to get access;• no authentication using Google account;• no m...
Google Cloud Messaging for Android     Requirements• Android 2.2 or higher;• Google account (OS version < Android 4.0.4);•...
Google Cloud Messaging for AndroidRequirements
Google Cloud Messaging for AndroidRequirements
Google Cloud Messaging for AndroidEnabling GCM          GCM                              Server                           ...
Google Cloud Messaging for Android            Enabling GCMimport com.google.android.gcm.GCMRegistrar;public class UAMobile...
Google Cloud Messaging for Android        Enabling GCMimport com.google.android.gcm.GCMBaseIntentService;public class GCMI...
Google Cloud Messaging for AndroidSending a message                                      1    GCM          A message with ...
Google Cloud Messaging for Android             Sending a message             Requesthttps://android.googleapis.com/gcm/sen...
Google Cloud Messaging for Android        Sending a message        Response{    "multicast_id": 112,    "success": 2,    "...
Google Cloud Messaging for Android        Sending a message        Clientimport com.google.android.gcm.GCMBaseIntentServic...
Google Cloud Messaging for Android      Unregistration• manually by sending an intent  com.google.android.c2dm.intent.UNRE...
Google Cloud Messaging for AndroidUnregistration                             Device not                           register...
Google Cloud Messaging for Android      Message states• sent;• stored (a device is offline);• collapsed (a device is offli...
Google Cloud Messaging for Android     Concepts• send-to-sync;• message with payload.
Google Cloud Messaging for Android     Features• no broadcasting;• no guarantees about delivery and order;• message multic...
Google Cloud Messaging for Android         How to migrate from C2DMClient• deliver a new version of your app;• send a flag...
Google Cloud Messaging for Android      GCM & APNS• no certificates;• one http address for development and production;• us...
Demo
Q&A
Upcoming SlideShare
Loading in...5
×

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

1,042

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,042
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
40
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. Google Cloud Messaging forAndroidShcheglov MaksymMTS1 at Magento inc.
  2. 2. Google Cloud Messaging for Android GCM & C2DM• no signup to get access;• no authentication using Google account;• no message quota.
  3. 3. 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).
  4. 4. Google Cloud Messaging for AndroidRequirements
  5. 5. Google Cloud Messaging for AndroidRequirements
  6. 6. Google Cloud Messaging for AndroidEnabling GCM GCM Server Sender ID, Application ID 2 1Registration ID Registration ID 3 Mobile phone
  7. 7. 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 } }}
  8. 8. 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); }}
  9. 9. Google Cloud Messaging for AndroidSending a message 1 GCM A message with API Server key, Registration ID 2 Mobile phone
  10. 10. Google Cloud Messaging for Android Sending a message Requesthttps://android.googleapis.com/gcm/sendHTTP headers:Content-Type:application/jsonAuthorization:key=AIzaSyAIpOT5VHEOthyrwKjwrNwwEVHQIgioypkHTTP body:{ “collapse_key” : “news_update”, “time_to_live” : 100, “delay_while_idle” : true, "data" : { ... }, "registration_ids" : [”ID1”, “ID2”, “ID3”],}
  11. 11. Google Cloud Messaging for Android Sending a message Response{ "multicast_id": 112, "success": 2, "failure": 1, "canonical_ids": 1, ”results": [ { “message_id": "1:2036" }, { "message_id": "1:7695", "registration_id": ”102" }, { "error": "NotRegistered"} ]}
  12. 12. Google Cloud Messaging for Android Sending a message Clientimport 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"); }}
  13. 13. Google Cloud Messaging for Android Unregistration• manually by sending an intent com.google.android.c2dm.intent.UNREGI STER;• 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.RECEIV E intents.
  14. 14. Google Cloud Messaging for AndroidUnregistration Device not registered error 5 1 4 GCM Server invalidate 2 3 Mobile phone
  15. 15. Google Cloud Messaging for Android Message states• sent;• stored (a device is offline);• collapsed (a device is offline & we have a new message);• throttled.
  16. 16. Google Cloud Messaging for Android Concepts• send-to-sync;• message with payload.
  17. 17. 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.
  18. 18. Google Cloud Messaging for Android How to migrate from C2DMClient• deliver a new version of your app;• send a flag with registration ID.Server• new endpoint;• API key in the Authorization header.
  19. 19. 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).
  20. 20. Demo
  21. 21. Q&A
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×