SlideShare a Scribd company logo
Google Cloud Messaging - Android
Swapnal Agrawal
• How to keep the data on your device app
- Updated & Fresh
Can use Notifications ?????
How to send notification
msg
data
How to send notification
• Polling
 App checks the server periodically
 Easy to implement
 Good for frequent content change
But……
It reduces bandwidth and battery resources
If there isn’t any new data, we’re still checking
How to send notification
• Pushing
 App waits for information to get sent to it.
 Constant Connection
 Less Battery Consumption
But…
A bit complex to implement
What is GCM?
 Google Cloud Messaging for Android (GCM) is a
service that allows you to send data from your server to
your users' Android-powered device.
 The GCM service handles all aspects of queueing of
messages and delivery to the target Android application
running on the target device
 GCM is completely free no matter how big your
messaging needs are, and there are no quotas.
How efficient is it?
 Easy to use
 It allows 3rd-party application servers to send messages
to their Android applications.
 An Android application on an Android device doesn't
need to be running to receive messages.
 Limitless Quotas
 Battery Efficiency
 Rich set of new API’s
Limitations of GCM
The device must be running 2.2 or greater.
The device must have the Marketplace
installed.
Your app needs additional permissions in
the manifest.
GCM Building Blocks
• Components :-
 Mobile Device
 3rd party App Server
 GCM Server
• Credentials :-
 SenderId
 ApplicationId
 RegistrationId
 Google User Account
 Sender Auth Token
GCM Registeration
Android Device
5. Intent Broadcast
Service
App
View
Application
Server
GCM
Service
App
View
1. Register for
Notification
2. Send
Registration ID
3. Send
Notification
4. Send
Message
GCM LifeCycle
• Enabling GCM.
An Android application running on a mobile device
registers to receive messages.
• Sending a message.
A 3rd-party application server sends messages to
the device.
• Receiving a message.
An Android application receives a message from a
GCM server.
Enabling GCM
 You should have one google account login
 If you already have existing projects, the first page you see will be
the Dashboard page. From there you can create a new project by opening
the project drop-down menu (upper left corner) and choosingOther
projects > Create.
 Click Create project. Your browser URL will change to something like:
https://code.google.com/apis/console/#project:219845360754
Enable the GCM service:
 In the main Google APIs Console page, select Services.
 Turn the Google Cloud Messaging toggle to ON.
 In the Terms of Service page, accept the terms.
Enabling GCM
Obtain API key as per the steps given at
http://developer.android.com/google/gcm/gs.html
Import com.google.android.gcm.GCMRegistrar;
@Override
protected void onCreate(Bundle
savedInstanceState)
{
GCMRegistrar.register(this, “219845360754”);
}
GCM Registration
GCM
GCM
Framework
Project Id
GCM – Android Manifest
<manifest package="com.example.gcm" ...>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application ...>
<receiver
android:name=".MyBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
GCM – Sending Message
Server Side Application :-
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
[..]
public Result sendMessage(final String device, final String message) throws
IOException
{
Sender sender = new Sender(getApiKey());
Message gcmMessage = new Message.Builder().addData("payload",
message)
.collapseKey("0").build(); return sender.send(gcmMessage, device, 5);
}
GCM – Receive Message
GCM
GCM
Framework
RegId {Intent}
• System receives the incoming message
and extracts the raw key/value pairs
• System passes key/value pairs to targeted
Android Application in a
com.google.android.c2dm.intent.RECEIVE
Intent as a set of extras
• Android application extracts the raw data
from the Intent by key and processes the
data
GCM – Receive Message
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.Sender;
[..]
public Result sendMessage(final String device, final String message) throws
IOException
{
Sender sender = new Sender(getApiKey());
Message gcmMessage = new Message.Builder().addData("payload",
message)
.collapseKey("0").build(); return sender.send(gcmMessage, device, 5);
}
References
• https://docs.google.com/presentation/d/1qQPT653uUrKFXYUxPE7gy-
5Kii0UupxS6K8TvAwfnXI/edit#slide=id.p74
• http://developer.android.com/google/gcm/gs.html
• http://developer.android.com/google/gcm/gcm.html
• https://bremen-
gtug.googlecode.com/svn/presentations/2012_12_03/Google%20Cloud%20
Messaging/template.html#3
• http://www.fppt.com (PPT templates)
GCM Android

More Related Content

What's hot

Gcm presentation
Gcm presentationGcm presentation
Gcm presentation
Niraj Singh
 
FCM & GCM
FCM & GCMFCM & GCM
FCM & GCM
Wesley Liu
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017
ketan Bordekar
 
GCM with Pushbots
GCM with PushbotsGCM with Pushbots
GCM with Pushbots
Ashish RAj
 
Push it! How to use Google Cloud Messaging in your Android App
Push it! How to use Google Cloud Messaging in your Android AppPush it! How to use Google Cloud Messaging in your Android App
Push it! How to use Google Cloud Messaging in your Android App
Achim Fischer
 
Firebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to DeviceFirebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to Device
Takuma Lee
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
Bhavana Sharma
 
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingPush Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Cumulations Technologies
 
Urban Airship & Android Application Integration Document
Urban Airship & Android Application Integration DocumentUrban Airship & Android Application Integration Document
Urban Airship & Android Application Integration Document
mobi fly
 
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Zeeshan Rahman
 
AutoMate+
AutoMate+AutoMate+
AutoMate+
Sanat Maharjan
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
Kanda Runapongsa Saikaew
 
Adventures in Serverless Backends
Adventures in Serverless BackendsAdventures in Serverless Backends
Adventures in Serverless Backends
MobileMonday Estonia
 
Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)
brendankowitz
 

What's hot (15)

Gcm presentation
Gcm presentationGcm presentation
Gcm presentation
 
FCM & GCM
FCM & GCMFCM & GCM
FCM & GCM
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017
 
GCM with Pushbots
GCM with PushbotsGCM with Pushbots
GCM with Pushbots
 
Push it! How to use Google Cloud Messaging in your Android App
Push it! How to use Google Cloud Messaging in your Android AppPush it! How to use Google Cloud Messaging in your Android App
Push it! How to use Google Cloud Messaging in your Android App
 
Firebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to DeviceFirebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to Device
 
Magda badita gcm
Magda badita  gcmMagda badita  gcm
Magda badita gcm
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud MessagingPush Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging
 
Urban Airship & Android Application Integration Document
Urban Airship & Android Application Integration DocumentUrban Airship & Android Application Integration Document
Urban Airship & Android Application Integration Document
 
Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...Urban Airship and Android Integration for Push Notification and In-App Notifi...
Urban Airship and Android Integration for Push Notification and In-App Notifi...
 
AutoMate+
AutoMate+AutoMate+
AutoMate+
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Adventures in Serverless Backends
Adventures in Serverless BackendsAdventures in Serverless Backends
Adventures in Serverless Backends
 
Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)Real time web applications with SignalR (BNE .NET UG)
Real time web applications with SignalR (BNE .NET UG)
 

Similar to GCM Android

GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for Android
Ranjitha R_14
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
Luca Morettoni
 
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
ijistjournal
 
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
Chinnayya Math
 
Google cloud messaging
Google cloud messagingGoogle cloud messaging
Google cloud messaging
Baburaj Annamalai
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud MessagingAshiq Uz Zoha
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceAndroid C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Lars Vogel
 
Remotetestingfeaturev1 160109071942
Remotetestingfeaturev1 160109071942Remotetestingfeaturev1 160109071942
Remotetestingfeaturev1 160109071942
Arunkumar H
 
Remotetestingfeature v1.1
Remotetestingfeature v1.1Remotetestingfeature v1.1
Remotetestingfeature v1.1
Arunkumar H
 
A Journey into Google Cloud Messaging
A Journey into Google Cloud MessagingA Journey into Google Cloud Messaging
A Journey into Google Cloud Messaging
Simone Pulcini, OCMJEA6 OCUP
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App Engine
Lars Vogel
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)
Mike Willbanks
 
GCCP Session #1 - Getting Started with GCP.pptx
GCCP Session #1 - Getting Started with GCP.pptxGCCP Session #1 - Getting Started with GCP.pptx
GCCP Session #1 - Getting Started with GCP.pptx
RamshaAshraf12
 
Push-Notification
Push-NotificationPush-Notification
Push-NotificationAmey Ruikar
 
Introductory Session.pdf
Introductory Session.pdfIntroductory Session.pdf
Introductory Session.pdf
GDSCPUP
 
Copy of Week #1
Copy of Week #1Copy of Week #1
Copy of Week #1
GDSCIIITDHARWAD
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
Fernando Cejas
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messagingFe
 

Similar to GCM Android (20)

GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for Android
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
 
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
 
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
A Google Cloud Solution Minus Dedicated Server - App Only (Server and Client)
 
Google cloud messaging
Google cloud messagingGoogle cloud messaging
Google cloud messaging
 
Gcm tutorial
Gcm tutorialGcm tutorial
Gcm tutorial
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud Messaging
 
Android C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen ConferenceAndroid C2DM Presentation at O'Reilly AndroidOpen Conference
Android C2DM Presentation at O'Reilly AndroidOpen Conference
 
Remotetestingfeaturev1 160109071942
Remotetestingfeaturev1 160109071942Remotetestingfeaturev1 160109071942
Remotetestingfeaturev1 160109071942
 
Remotetestingfeature v1.1
Remotetestingfeature v1.1Remotetestingfeature v1.1
Remotetestingfeature v1.1
 
A Journey into Google Cloud Messaging
A Journey into Google Cloud MessagingA Journey into Google Cloud Messaging
A Journey into Google Cloud Messaging
 
Android Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App EngineAndroid Cloud to Device Messaging with the Google App Engine
Android Cloud to Device Messaging with the Google App Engine
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)
 
Presentation
PresentationPresentation
Presentation
 
GCCP Session #1 - Getting Started with GCP.pptx
GCCP Session #1 - Getting Started with GCP.pptxGCCP Session #1 - Getting Started with GCP.pptx
GCCP Session #1 - Getting Started with GCP.pptx
 
Push-Notification
Push-NotificationPush-Notification
Push-Notification
 
Introductory Session.pdf
Introductory Session.pdfIntroductory Session.pdf
Introductory Session.pdf
 
Copy of Week #1
Copy of Week #1Copy of Week #1
Copy of Week #1
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device Messaging
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messaging
 

GCM Android

  • 1. Google Cloud Messaging - Android Swapnal Agrawal
  • 2. • How to keep the data on your device app - Updated & Fresh Can use Notifications ????? How to send notification msg data
  • 3. How to send notification • Polling  App checks the server periodically  Easy to implement  Good for frequent content change But…… It reduces bandwidth and battery resources If there isn’t any new data, we’re still checking
  • 4. How to send notification • Pushing  App waits for information to get sent to it.  Constant Connection  Less Battery Consumption But… A bit complex to implement
  • 5. What is GCM?  Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device.  The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device  GCM is completely free no matter how big your messaging needs are, and there are no quotas.
  • 6. How efficient is it?  Easy to use  It allows 3rd-party application servers to send messages to their Android applications.  An Android application on an Android device doesn't need to be running to receive messages.  Limitless Quotas  Battery Efficiency  Rich set of new API’s
  • 7. Limitations of GCM The device must be running 2.2 or greater. The device must have the Marketplace installed. Your app needs additional permissions in the manifest.
  • 8. GCM Building Blocks • Components :-  Mobile Device  3rd party App Server  GCM Server • Credentials :-  SenderId  ApplicationId  RegistrationId  Google User Account  Sender Auth Token
  • 9. GCM Registeration Android Device 5. Intent Broadcast Service App View Application Server GCM Service App View 1. Register for Notification 2. Send Registration ID 3. Send Notification 4. Send Message
  • 10. GCM LifeCycle • Enabling GCM. An Android application running on a mobile device registers to receive messages. • Sending a message. A 3rd-party application server sends messages to the device. • Receiving a message. An Android application receives a message from a GCM server.
  • 11. Enabling GCM  You should have one google account login  If you already have existing projects, the first page you see will be the Dashboard page. From there you can create a new project by opening the project drop-down menu (upper left corner) and choosingOther projects > Create.  Click Create project. Your browser URL will change to something like: https://code.google.com/apis/console/#project:219845360754 Enable the GCM service:  In the main Google APIs Console page, select Services.  Turn the Google Cloud Messaging toggle to ON.  In the Terms of Service page, accept the terms.
  • 12. Enabling GCM Obtain API key as per the steps given at http://developer.android.com/google/gcm/gs.html
  • 13. Import com.google.android.gcm.GCMRegistrar; @Override protected void onCreate(Bundle savedInstanceState) { GCMRegistrar.register(this, “219845360754”); } GCM Registration GCM GCM Framework Project Id
  • 14. GCM – Android Manifest <manifest package="com.example.gcm" ...> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /> <application ...> <receiver android:name=".MyBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.example.gcm" /> </intent-filter> </receiver> <service android:name=".GCMIntentService" /> </application> </manifest>
  • 15. GCM – Sending Message Server Side Application :- import com.google.android.gcm.server.Message; import com.google.android.gcm.server.Result; import com.google.android.gcm.server.Sender; [..] public Result sendMessage(final String device, final String message) throws IOException { Sender sender = new Sender(getApiKey()); Message gcmMessage = new Message.Builder().addData("payload", message) .collapseKey("0").build(); return sender.send(gcmMessage, device, 5); }
  • 16. GCM – Receive Message GCM GCM Framework RegId {Intent} • System receives the incoming message and extracts the raw key/value pairs • System passes key/value pairs to targeted Android Application in a com.google.android.c2dm.intent.RECEIVE Intent as a set of extras • Android application extracts the raw data from the Intent by key and processes the data
  • 17. GCM – Receive Message import com.google.android.gcm.server.Message; import com.google.android.gcm.server.Result; import com.google.android.gcm.server.Sender; [..] public Result sendMessage(final String device, final String message) throws IOException { Sender sender = new Sender(getApiKey()); Message gcmMessage = new Message.Builder().addData("payload", message) .collapseKey("0").build(); return sender.send(gcmMessage, device, 5); }
  • 18. References • https://docs.google.com/presentation/d/1qQPT653uUrKFXYUxPE7gy- 5Kii0UupxS6K8TvAwfnXI/edit#slide=id.p74 • http://developer.android.com/google/gcm/gs.html • http://developer.android.com/google/gcm/gcm.html • https://bremen- gtug.googlecode.com/svn/presentations/2012_12_03/Google%20Cloud%20 Messaging/template.html#3 • http://www.fppt.com (PPT templates)