Your SlideShare is downloading. ×
Максим Щеглов - Google Cloud Messaging for Android
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

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

980
views

Published on


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

No Downloads
Views
Total Views
980
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
36
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Google Cloud Messaging forAndroidShcheglov MaksymMTS1 at Magento inc.
  • 2. Google Cloud Messaging for Android GCM & C2DM• no signup to get access;• no authentication using Google account;• no message quota.
  • 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. Google Cloud Messaging for AndroidRequirements
  • 5. Google Cloud Messaging for AndroidRequirements
  • 6. Google Cloud Messaging for AndroidEnabling GCM GCM Server Sender ID, Application ID 2 1Registration ID Registration ID 3 Mobile phone
  • 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. 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. Google Cloud Messaging for AndroidSending a message 1 GCM A message with API Server key, Registration ID 2 Mobile phone
  • 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. 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. 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. 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. Google Cloud Messaging for AndroidUnregistration Device not registered error 5 1 4 GCM Server invalidate 2 3 Mobile phone
  • 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. Google Cloud Messaging for Android Concepts• send-to-sync;• message with payload.
  • 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. 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. 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. Demo
  • 21. Q&A