SlideShare une entreprise Scribd logo
•Google Cloud Messaging for Android (GCM) is a
free service that helps developers send data from
servers to their Android applications on Android
devices.
•Message containing up to 4kb of payload data.
•The GCM service handles all aspects of queuing of
messages and delivery to the target Android
application running on the target device.
•It doesn’t necessary that your application in
running state 24X7.
1. Application Server.

2. Google Account.
3. Android Phone/ emulator(Google API).
1. Registration ID- An ID issued by the GCM servers to the Android
application that allows it to receive messages. Once the Android application has
the registration ID, it sends it to the 3rd-party application server, which uses it
to identify each device that has registered to receive messages for a given
Android application. In other words, a registration ID is tied to a particular
Android application running on a particular device.

2. Sender Auth Token- An API key that is saved on the 3rd-party
application server that gives the application server authorized access to Google
services. The API key is included in the header of POST requests that send
messages.

3. Sender ID- A project ID you acquire from the API console The sender ID
is used in the registration process to identify an Android application that is
permitted to send messages to the device.

4. Pay Load – your data.
1.Client will send
activation request, via
our application
2.Client will receive
response with unique
Registration ID.
5. GCM server push the
data with GCM
technology
3.Client need to send
this Registration ID, to
our app server. This
registration ID is used
to send data to the
phone.

4.When ever server have
any message for a
particular device , it send
the request to the GCM
server using Registration
ID.
You need to create a Google API project open the following link
https://code.google.com/apis/console/
and
activate GCM API service to your project
Note down:
1. Project Number(SENDER ID)
2. API key(Sender Auth Token)
Permission:
<manifest package=“in.androidshivendra.gcm" ...>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name=“in.androidshivendra.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="in.androidshivendra.gcm.permission.C2D_MESSAGE" />

<receiver android:name=".GBroadcastReceiver"
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="in.androidshivendra.gcm" />
</intent-filter>
</receiver>
Registration :
Intent registrationIntent = new
Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app", PendingIntent.getBroadcast(v.getContext(),
0, new Intent(), 0));
registrationIntent.putExtra("sender", SenderID);
startService(registrationIntent);
Deactivation:
Intent unregIntent = new
Intent("com.google.android.c2dm.intent.UNREGISTER");
unregIntent.putExtra("app", PendingIntent.getBroadcast(v.getContext(), 0, ne
w Intent(), 0));
startService(unregIntent);
Create a Broadcaster Receiver class:
GBroadcastReceiver
public class GBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getAction();
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
String registrationId = intent.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
String unregistered = intent.getStringExtra("unregistered");
}
else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
String data1 = intent.getStringExtra(“data1");
String data2 = intent.getStringExtra(“data2");
}
} finally {
}}}
Processing
(action.equals("com.google.android.c2dm.intent.REGISTRATION"))
String error = intent.getStringExtra("error")
If (error.equals.(“~~~~~~~~~”))
SERVICE_NOT_AVAILABLE The device can't read the response, or there was a
500/503 from the server that can be retried later. The Android application should
use exponential back-off and retry.
•ACCOUNT_MISSING-There is no Google account on the phone. The Android
application should ask the user to open the account manager and add a Google
account. Fix on the device side.
•AUTHENTICATION_FAILED-Bad Google Account password. The Android
application should ask the user to enter his/her Google Account password, and let
the user retry manually later. Fix on the device side.
•INVALID_SENDER-The sender account is not recognized. This must be fixed on
the Android application side. The developer must fix the application to provide the
right sender extra in thecom.google.android.c2dm.intent.REGISTER intent.
PHONE_REGISTRATION_ERROR-Incorrect phone registration with Google.
This phone doesn't currently support
GCM.INVALID_PARAMETERS-The request sent by the phone does not contain
the expected parameters. This phone doesn't currently support GCM.
Server implementation is via HTTP request :
To send a message, the application server issues a POST request to
https://android.googleapis.com/gcm/send.
A message request is made of 2 parts:
HTTP header and HTTP body.
The HTTP header
1.Authorization: key=YOUR_API_KEY
2. Content-Type: application/json for JSON; application/x-www-formurlencoded;charset=UTF-8 for plain text.
HTTP Body:
1. registration_id
2. data.<key>
Happy Android Programming
By: Shivendra
The Android Trainer

Contenu connexe

Tendances

GCM Android
GCM AndroidGCM Android
GCM Android
aswapnal
 
Максим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidМаксим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for Android
UA Mobile
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in android
RIA RUI Society
 
What is Google App Engine
What is Google App EngineWhat is Google App Engine
What is Google App Engine
Chris Schalk
 

Tendances (20)

google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
GCM Android
GCM AndroidGCM Android
GCM Android
 
Максим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidМаксим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for Android
 
FCM & GCM
FCM & GCMFCM & GCM
FCM & GCM
 
Introduction to google cloud messaging in android
Introduction to google cloud messaging in androidIntroduction to google cloud messaging in android
Introduction to google cloud messaging in android
 
Firebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to DeviceFirebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to Device
 
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
 
Magda badita gcm
Magda badita  gcmMagda badita  gcm
Magda badita gcm
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
apidays LIVE Australia 2020 - Building a scalable API platform for an IoT eco...
apidays LIVE Australia 2020 - Building a scalable API platform for an IoT eco...apidays LIVE Australia 2020 - Building a scalable API platform for an IoT eco...
apidays LIVE Australia 2020 - Building a scalable API platform for an IoT eco...
 
Developing Android Client Apps via SyncAdapter
Developing Android Client Apps via SyncAdapterDeveloping Android Client Apps via SyncAdapter
Developing Android Client Apps via SyncAdapter
 
Google App Engine's Latest Features
Google App Engine's Latest FeaturesGoogle App Engine's Latest Features
Google App Engine's Latest Features
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapter
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
What is Google App Engine
What is Google App EngineWhat is Google App Engine
What is Google App Engine
 
Google App Engine tutorial
Google App Engine tutorialGoogle App Engine tutorial
Google App Engine tutorial
 
Hello SMS!
Hello SMS!Hello SMS!
Hello SMS!
 
What is Google App Engine?
What is Google App Engine?What is Google App Engine?
What is Google App Engine?
 
Spring '22 SFMC Release Notes
Spring '22 SFMC Release NotesSpring '22 SFMC Release Notes
Spring '22 SFMC Release Notes
 

Similaire à Gcm tutorial

Khadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_DocumentationKhadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_Documentation
Khadija Mohammed
 
Push-Notification
Push-NotificationPush-Notification
Push-Notification
Amey Ruikar
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messaging
Fe
 

Similaire à Gcm tutorial (20)

Google cloud messaging
Google cloud messagingGoogle cloud messaging
Google cloud messaging
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for Android
 
A Journey into Google Cloud Messaging
A Journey into Google Cloud MessagingA Journey into Google Cloud Messaging
A Journey into Google Cloud Messaging
 
ANDROID APPLICATION FOR PASSWORDLESS LOGIN FOR WEB APPLICATIONS
ANDROID APPLICATION FOR PASSWORDLESS LOGIN FOR WEB APPLICATIONSANDROID APPLICATION FOR PASSWORDLESS LOGIN FOR WEB APPLICATIONS
ANDROID APPLICATION FOR PASSWORDLESS LOGIN FOR WEB APPLICATIONS
 
SMS retriever API
SMS retriever APISMS retriever API
SMS retriever API
 
Khadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_DocumentationKhadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_Documentation
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
 
Introduction to OAuth2
Introduction to OAuth2Introduction to OAuth2
Introduction to OAuth2
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
 
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)
 
Android Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG StockholmAndroid Cloud to Device Messaging Framework at GTUG Stockholm
Android Cloud to Device Messaging Framework at GTUG Stockholm
 
Push-Notification
Push-NotificationPush-Notification
Push-Notification
 
CIS 2015- SSO for Mobile and Web Apps- Ashish Jain
CIS 2015- SSO for Mobile and Web Apps- Ashish JainCIS 2015- SSO for Mobile and Web Apps- Ashish Jain
CIS 2015- SSO for Mobile and Web Apps- Ashish Jain
 
CIS 2015 SSO for Mobile and Web Apps Ashish Jain
CIS 2015 SSO for Mobile and Web Apps Ashish JainCIS 2015 SSO for Mobile and Web Apps Ashish Jain
CIS 2015 SSO for Mobile and Web Apps Ashish Jain
 
CIS 2015 Mobile SSO
CIS 2015 Mobile SSOCIS 2015 Mobile SSO
CIS 2015 Mobile SSO
 
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
 
Big commerce app development
Big commerce app developmentBig commerce app development
Big commerce app development
 
Toll pay
Toll payToll pay
Toll pay
 
Toll pay
Toll payToll pay
Toll pay
 

Dernier

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Dernier (20)

UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Transforming The New York Times: Empowering Evolution through UX
Transforming The New York Times: Empowering Evolution through UXTransforming The New York Times: Empowering Evolution through UX
Transforming The New York Times: Empowering Evolution through UX
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 

Gcm tutorial

  • 1.
  • 2. •Google Cloud Messaging for Android (GCM) is a free service that helps developers send data from servers to their Android applications on Android devices. •Message containing up to 4kb of payload data. •The GCM service handles all aspects of queuing of messages and delivery to the target Android application running on the target device. •It doesn’t necessary that your application in running state 24X7.
  • 3. 1. Application Server. 2. Google Account. 3. Android Phone/ emulator(Google API).
  • 4. 1. Registration ID- An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device. 2. Sender Auth Token- An API key that is saved on the 3rd-party application server that gives the application server authorized access to Google services. The API key is included in the header of POST requests that send messages. 3. Sender ID- A project ID you acquire from the API console The sender ID is used in the registration process to identify an Android application that is permitted to send messages to the device. 4. Pay Load – your data.
  • 5. 1.Client will send activation request, via our application 2.Client will receive response with unique Registration ID. 5. GCM server push the data with GCM technology 3.Client need to send this Registration ID, to our app server. This registration ID is used to send data to the phone. 4.When ever server have any message for a particular device , it send the request to the GCM server using Registration ID.
  • 6. You need to create a Google API project open the following link https://code.google.com/apis/console/ and activate GCM API service to your project Note down: 1. Project Number(SENDER ID) 2. API key(Sender Auth Token)
  • 7. Permission: <manifest package=“in.androidshivendra.gcm" ...> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name=“in.androidshivendra.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="in.androidshivendra.gcm.permission.C2D_MESSAGE" /> <receiver android:name=".GBroadcastReceiver" 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="in.androidshivendra.gcm" /> </intent-filter> </receiver>
  • 8. Registration : Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER"); registrationIntent.putExtra("app", PendingIntent.getBroadcast(v.getContext(), 0, new Intent(), 0)); registrationIntent.putExtra("sender", SenderID); startService(registrationIntent); Deactivation: Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER"); unregIntent.putExtra("app", PendingIntent.getBroadcast(v.getContext(), 0, ne w Intent(), 0)); startService(unregIntent);
  • 9. Create a Broadcaster Receiver class: GBroadcastReceiver public class GBroadcastReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { try { String action = intent.getAction(); if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) { String registrationId = intent.getStringExtra("registration_id"); String error = intent.getStringExtra("error"); String unregistered = intent.getStringExtra("unregistered"); } else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) { String data1 = intent.getStringExtra(“data1"); String data2 = intent.getStringExtra(“data2"); } } finally { }}}
  • 10. Processing (action.equals("com.google.android.c2dm.intent.REGISTRATION")) String error = intent.getStringExtra("error") If (error.equals.(“~~~~~~~~~”)) SERVICE_NOT_AVAILABLE The device can't read the response, or there was a 500/503 from the server that can be retried later. The Android application should use exponential back-off and retry. •ACCOUNT_MISSING-There is no Google account on the phone. The Android application should ask the user to open the account manager and add a Google account. Fix on the device side. •AUTHENTICATION_FAILED-Bad Google Account password. The Android application should ask the user to enter his/her Google Account password, and let the user retry manually later. Fix on the device side. •INVALID_SENDER-The sender account is not recognized. This must be fixed on the Android application side. The developer must fix the application to provide the right sender extra in thecom.google.android.c2dm.intent.REGISTER intent. PHONE_REGISTRATION_ERROR-Incorrect phone registration with Google. This phone doesn't currently support GCM.INVALID_PARAMETERS-The request sent by the phone does not contain the expected parameters. This phone doesn't currently support GCM.
  • 11. Server implementation is via HTTP request : To send a message, the application server issues a POST request to https://android.googleapis.com/gcm/send. A message request is made of 2 parts: HTTP header and HTTP body. The HTTP header 1.Authorization: key=YOUR_API_KEY 2. Content-Type: application/json for JSON; application/x-www-formurlencoded;charset=UTF-8 for plain text. HTTP Body: 1. registration_id 2. data.<key>
  • 12. Happy Android Programming By: Shivendra The Android Trainer