SlideShare una empresa de Scribd logo
1 de 12
•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

Más contenido relacionado

La actualidad más candente

google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messagingBhavana Sharma
 
GCM Android
GCM AndroidGCM Android
GCM Androidaswapnal
 
Максим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidМаксим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidUA 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 androidRIA RUI Society
 
Firebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to DeviceFirebase Cloud Messaging Device to Device
Firebase Cloud Messaging Device to DeviceTakuma Lee
 
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 AppAchim Fischer
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App EngineAndrea Spadaccini
 
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...apidays
 
Developing Android Client Apps via SyncAdapter
Developing Android Client Apps via SyncAdapterDeveloping Android Client Apps via SyncAdapter
Developing Android Client Apps via SyncAdapterAnatoliy Kaverin
 
Google App Engine's Latest Features
Google App Engine's Latest FeaturesGoogle App Engine's Latest Features
Google App Engine's Latest FeaturesChris Schalk
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapterAlex Tumanoff
 
What is Google App Engine
What is Google App EngineWhat is Google App Engine
What is Google App EngineChris Schalk
 
What is Google App Engine?
What is Google App Engine?What is Google App Engine?
What is Google App Engine?weschwee
 
Spring '22 SFMC Release Notes
Spring '22 SFMC Release NotesSpring '22 SFMC Release Notes
Spring '22 SFMC Release NotesKimmyCoburn1
 

La actualidad más candente (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
 

Similar a Gcm tutorial

GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for AndroidRanjitha R_14
 
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 APPLICATIONSJournal For Research
 
SMS retriever API
SMS retriever APISMS retriever API
SMS retriever APIZhe-Hao Hu
 
Khadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_DocumentationKhadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_DocumentationKhadija Mohammed
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloudfirenze-gtug
 
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
 
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 StockholmJohan Nilsson
 
Push-Notification
Push-NotificationPush-Notification
Push-NotificationAmey Ruikar
 
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 JainCloudIDSummit
 
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 JainCloudIDSummit
 
CIS 2015 Mobile SSO
CIS 2015 Mobile SSOCIS 2015 Mobile SSO
CIS 2015 Mobile SSOAshish Jain
 
Android Cloud To Device Messaging
Android Cloud To Device MessagingAndroid Cloud To Device Messaging
Android Cloud To Device MessagingFernando Cejas
 
Android cloud to device messaging
Android cloud to device messagingAndroid cloud to device messaging
Android cloud to device messagingFe
 
Big commerce app development
Big commerce app developmentBig commerce app development
Big commerce app developmentNascenia IT
 

Similar a 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
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

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