SlideShare uma empresa Scribd logo
1 de 23
GCMGoogle Cloud Messaging for Android
Niraj Singh
GCM: Introduction
• GCM (Google Cloud Messaging) is a free service that helps developers
send data from servers to their Android applications on Android devices.
• Using GCM we can push lightweight message to applications telling that
there is new data to be fetched from the server or
a message containing up to 4kb of payload data (e g: instant messaging
apps).
• This can eliminate continuous query to server for updates using
background services
GCM: Characteristics
• Allows 3rd-party application servers to send messages to their Android
applications.
• GCM makes no guarantees about delivery or the order of messages.
• Application on an Android device doesn't need to be running to receive
messages.
• Requires devices running Android 2.2 or higher (with Google Play Store
application installed), or an emulator running Android 2.2 with Google APIs.
• Uses an existing connection for Google services. For pre-3.0
devices, this requires users to set up their Google account on their mobile
devices. A Google account is not a requirement on devices running Android
4.0.4 or higher.
GCM: Architectural Overview
Key Terms: key terms and concepts involved in GCM are divided
into these categories.
• Components -The physical entities that playa role in GCM.
• Credentials -The IDs and tokens that are used in different stages of GCM
to ensure that all parties have been authenticated, and that the message
is going to the correct place.
GCM Architecture: Components
Components
• Mobile Device -The device that is running an Android application that uses
GCM. This must be a 2.2 Android device that has Google Play Store installed,
and it must have at least one logged in Google account if the device is running a
version lower than Android 4.0.4. Alternatively, for testing you can use an
emulator running Android 2.2 with Google APIs.
• 3rd-party Application Server - An application server that developers set up as
part of implementing GCM in their applications. The 3rd-party application
server sends data to an Android application on the device via the GCM server.
• GCM Servers - The Google servers involved in taking messages from the 3rd-
party application server and sending them to the device.
GCM Architecture: Components
GCM Architecture: Credentials
Credentials
• Sender ID - A project ID you acquire from the API console to identify an
Android application that is permitted to send messages to the device.
• Application ID - The Android application that is registering to receive
messages.
• Registration ID - An ID issued by the GCM servers to the Android
application that allows it to receive messages.
• Google User Account - For GCM to work, the mobile device must include
at least one Google account if the device is running a version lower than
Android 4.0.4.
• 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.
GCM: Implementation
• 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. (we'll do it with php)
• Receiving a Message - An Android application receives a message from a
GCM server.
GCM: Implementation Steps (1)
• Goto https://code.google.com/apis/console
• Create a project - Project_Name
• Browser link has changed as https://code.google.com/apis/console/?
pli=1#project:351708780651:services
• it contains project id (94384365614 in this example)
• We required that in our application as sender id.
GCM: Implementation Steps (2)
• 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.
GCM: Implementation Steps (3)
• In the main Google APIs Console page, select API Access. Now you can see
there is API key if you use that key your application can receive messages from
any server & if you want to restrict servers you can generate new server key
using button there as “Create new server key…”.
GCM: Implementation Steps (3.1)
Now we have Sender ID and API KEY
• Sender ID - 351708780651
• API KEY - AIzaSyBFhGpJswkvMxMTElfAQeMUskG13ii7s1Q
GCM: Implementation Steps (4)
• Create new Android Project
• Copy the gcm.jar file from - SDK~PATH/extras/google/gcm/gcm-client/dist directory to your
application classpath. As external jar.
GCM: Implementation Steps (6)
Permissions in Manifest
• INTERNET – To make your app use internet services.
<uses-permission android:name="android.permission.INTERNET" />
• ACCESS_NETWORK_STATE – To access network state (used to detect internet
status)
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
• GET_ACCOUNTS – Required as GCM needs google account
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
GCM: Implementation Steps (6)
Permissions in Manifest
• WAKE_LOCK – Needed if your app need to wake your device when it sleeps
<uses-permission android:name="android.permission.WAKE_LOCK" />
• VIBRATE – Needed if your support vibration when receiving notification Also add
some broadcast receivers as mentioned below.
<uses-permission android:name="android.permission.VIBRATE" />
GCM: Implementation Steps (7)
• Add GCM Receiver
BroadcastReceiver that will receive intent from GCM Services and handle them
To the custom Intent Services.
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.androidexample.gcm" />
</intent-filter>
</receiver>
GCM: Implementation Steps (9)
• Add GCMIntentService extending GCMBaseIntentService and add the service in
Manifest
<service android:name="com.androidexample.gcm.GCMIntentService" />
public class GCMIntentService extends GCMBaseIntentService {
 /**
* Method called on device registered
**/
@Override
protected void onRegistered(Context context, String registrationId) {
 /**
* Method called on device unregistred
* */
@Override
protected void onUnregistered(Context context, String registrationId) {
GCM: Implementation Steps (9)
• Add GCMIntentService extending GCMBaseIntentService and add the service in
Manifest
 /**
* Method called on Receiving a new message from GCM server
* */
@Override
protected void onMessage(Context context, Intent intent) {
 /**
* Method called on receiving a deleted message
* */
@Override
protected void onDeletedMessages(Context context, int total) {
GCM: Implementation Steps (10)
• Register:
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
// Make sure the manifest permissions was properly set
GCMRegistrar.checkManifest(this);
// Get GCM registration id
final String regId = GCMRegistrar.getRegistrationId(this);
// Check if regid already presents
if (regId.equals("")) {
// Register with GCM
GCMRegistrar.register(this, Config.GOOGLE_SENDER_ID);
} else {
GCM: Implementation Steps (10)
 Register:
// Device is already registered on GCM Server
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
Toast.makeText(getApplicationContext(), "Already registered with GCM Server",
Toast.LENGTH_LONG).show();
}
GCM: Implementation Steps (10)
• Unregister:
// Unregister Broadcast Receiver
unregisterReceiver(mHandleMessageReceiver);
GCM: Implementation Steps (11)
• Receive Message
/**
* Method called on Receiving a new message from GCM server
* */
@Override
protected void onMessage(Context context, Intent intent) {
if(aController == null)
aController = (Controller) getApplicationContext();
Log.i(TAG, "Received message");
String message = intent.getExtras().getString("price");
aController.displayMessageOnScreen(context, message);
// notifies user
generateNotification(context, message);
}
GCM: Implementation Steps (12)
• Send Message from Server
//Sending Push Notification
function send_push_notification($registatoin_ids, $message) {
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);

Mais conteúdo relacionado

Mais procurados

GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017ketan Bordekar
 
Максим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidМаксим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidUA Mobile
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messagingBhavana Sharma
 
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
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for AndroidRanjitha R_14
 
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
 
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew KurniadiID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew KurniadiDicoding
 
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 MessagingCumulations Technologies
 
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
 
Urban Airship & Android Application Integration Document
Urban Airship & Android Application Integration DocumentUrban Airship & Android Application Integration Document
Urban Airship & Android Application Integration Documentmobi fly
 
Google App Engine's Latest Features
Google App Engine's Latest FeaturesGoogle App Engine's Latest Features
Google App Engine's Latest FeaturesChris Schalk
 
Google app engine introduction
Google app engine introductionGoogle app engine introduction
Google app engine introductionrajsandhu1989
 

Mais procurados (20)

Gcm tutorial
Gcm tutorialGcm tutorial
Gcm tutorial
 
GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017GOOGLE CLOUD MESSAGING PPT 2017
GOOGLE CLOUD MESSAGING PPT 2017
 
Максим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for AndroidМаксим Щеглов - Google Cloud Messaging for Android
Максим Щеглов - Google Cloud Messaging for Android
 
google cloud messaging
google cloud messaginggoogle cloud messaging
google cloud messaging
 
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
 
GCM Technology for Android
GCM Technology for AndroidGCM Technology for Android
GCM Technology for Android
 
Magda badita gcm
Magda badita  gcmMagda badita  gcm
Magda badita gcm
 
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
 
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew KurniadiID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
ID Android TechTalk Series #6 : Google Service and Gradle - Andrew Kurniadi
 
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
 
Google cloud messaging
Google cloud messagingGoogle cloud messaging
Google cloud messaging
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
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...
 
Urban Airship & Android Application Integration Document
Urban Airship & Android Application Integration DocumentUrban Airship & Android Application Integration Document
Urban Airship & Android Application Integration Document
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Google App Engine's Latest Features
Google App Engine's Latest FeaturesGoogle App Engine's Latest Features
Google App Engine's Latest Features
 
Google app engine introduction
Google app engine introductionGoogle app engine introduction
Google app engine introduction
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 

Destaque

Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud MessagingArvind Devaraj
 
Ankara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud Sunumu
Ankara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud SunumuAnkara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud Sunumu
Ankara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud Sunumuİbrahim Gürses
 
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 EngineLars Vogel
 
secure data retrieval for decentralized disruption-tolerant military networks
secure data retrieval for decentralized disruption-tolerant military networkssecure data retrieval for decentralized disruption-tolerant military networks
secure data retrieval for decentralized disruption-tolerant military networksswathi78
 
Eucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud ComputingEucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud Computingclive boulton
 
Open Source Cloud Computing -Eucalyptus
Open Source Cloud Computing -EucalyptusOpen Source Cloud Computing -Eucalyptus
Open Source Cloud Computing -EucalyptusSameer Naik
 
Money pad the future wallet
Money pad the future walletMoney pad the future wallet
Money pad the future walletLeelakh Sachdeva
 
MoneyPad:The Future Wallet
MoneyPad:The Future WalletMoneyPad:The Future Wallet
MoneyPad:The Future Walletjolly9293
 
5G Wireless Technology
5G Wireless Technology5G Wireless Technology
5G Wireless TechnologyNiki Upadhyay
 

Destaque (13)

Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud Messaging
 
Ankara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud Sunumu
Ankara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud SunumuAnkara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud Sunumu
Ankara Cloud Meetup 6. Etkinlik Scaling Real-Time Messaging on Cloud Sunumu
 
Pitch that matters
Pitch that mattersPitch that matters
Pitch that matters
 
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
 
secure data retrieval for decentralized disruption-tolerant military networks
secure data retrieval for decentralized disruption-tolerant military networkssecure data retrieval for decentralized disruption-tolerant military networks
secure data retrieval for decentralized disruption-tolerant military networks
 
Eucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud ComputingEucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud Computing
 
cloude computing
cloude computingcloude computing
cloude computing
 
Java project-presentation
Java project-presentationJava project-presentation
Java project-presentation
 
Open Source Cloud Computing -Eucalyptus
Open Source Cloud Computing -EucalyptusOpen Source Cloud Computing -Eucalyptus
Open Source Cloud Computing -Eucalyptus
 
Money pad the future wallet
Money pad the future walletMoney pad the future wallet
Money pad the future wallet
 
Money pad ppt
Money pad pptMoney pad ppt
Money pad ppt
 
MoneyPad:The Future Wallet
MoneyPad:The Future WalletMoneyPad:The Future Wallet
MoneyPad:The Future Wallet
 
5G Wireless Technology
5G Wireless Technology5G Wireless Technology
5G Wireless Technology
 

Semelhante a Gcm presentation

Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud MessagingAshiq Uz Zoha
 
Remotetestingfeaturev1 160109071942
Remotetestingfeaturev1 160109071942Remotetestingfeaturev1 160109071942
Remotetestingfeaturev1 160109071942Arunkumar H
 
Remotetestingfeature v1.1
Remotetestingfeature v1.1Remotetestingfeature v1.1
Remotetestingfeature v1.1Arunkumar H
 
Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...
Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...
Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...99X Technology
 
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 chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloudfirenze-gtug
 
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
 
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 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
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingJohan Nilsson
 
Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...
Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...
Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...Amaaira Johns
 
Push Notification in IBM MobileFirst Xamarin SDK
Push Notification in IBM MobileFirst Xamarin SDKPush Notification in IBM MobileFirst Xamarin SDK
Push Notification in IBM MobileFirst Xamarin SDKAjay Chebbi
 
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
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorialmaamir farooq
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorialmaamir farooq
 

Semelhante a Gcm presentation (20)

GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud Messaging
 
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
 
Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...
Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...
Colombo Mobile Developer MeetUp - Building Scalable Cloud Connected Mobile Ap...
 
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)
 
Presentation
PresentationPresentation
Presentation
 
GCM demo on Android
GCM demo on AndroidGCM demo on Android
GCM demo on Android
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
 
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
 
Khadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_DocumentationKhadamaty_MOI_Smart_Gov_Award_Documentation
Khadamaty_MOI_Smart_Gov_Award_Documentation
 
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
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device Messaging
 
Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...
Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...
Get Well Prepared for Google Professional Cloud Developer (GCP-PCD) Certifica...
 
Push Notification in IBM MobileFirst Xamarin SDK
Push Notification in IBM MobileFirst Xamarin SDKPush Notification in IBM MobileFirst Xamarin SDK
Push Notification in IBM MobileFirst Xamarin SDK
 
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 ...
 
Android broadcast receiver tutorial
Android broadcast receiver  tutorialAndroid broadcast receiver  tutorial
Android broadcast receiver tutorial
 
Android broadcast receiver tutorial
Android broadcast receiver   tutorialAndroid broadcast receiver   tutorial
Android broadcast receiver tutorial
 

Último

Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...nishasame66
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsChandrakantDivate1
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsChandrakantDivate1
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfCWS Technology
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesChandrakantDivate1
 

Último (6)

Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
Satara Call girl escort *74796//13122* Call me punam call girls 24*7hour avai...
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 

Gcm presentation

  • 1. GCMGoogle Cloud Messaging for Android Niraj Singh
  • 2. GCM: Introduction • GCM (Google Cloud Messaging) is a free service that helps developers send data from servers to their Android applications on Android devices. • Using GCM we can push lightweight message to applications telling that there is new data to be fetched from the server or a message containing up to 4kb of payload data (e g: instant messaging apps). • This can eliminate continuous query to server for updates using background services
  • 3. GCM: Characteristics • Allows 3rd-party application servers to send messages to their Android applications. • GCM makes no guarantees about delivery or the order of messages. • Application on an Android device doesn't need to be running to receive messages. • Requires devices running Android 2.2 or higher (with Google Play Store application installed), or an emulator running Android 2.2 with Google APIs. • Uses an existing connection for Google services. For pre-3.0 devices, this requires users to set up their Google account on their mobile devices. A Google account is not a requirement on devices running Android 4.0.4 or higher.
  • 4. GCM: Architectural Overview Key Terms: key terms and concepts involved in GCM are divided into these categories. • Components -The physical entities that playa role in GCM. • Credentials -The IDs and tokens that are used in different stages of GCM to ensure that all parties have been authenticated, and that the message is going to the correct place.
  • 5. GCM Architecture: Components Components • Mobile Device -The device that is running an Android application that uses GCM. This must be a 2.2 Android device that has Google Play Store installed, and it must have at least one logged in Google account if the device is running a version lower than Android 4.0.4. Alternatively, for testing you can use an emulator running Android 2.2 with Google APIs. • 3rd-party Application Server - An application server that developers set up as part of implementing GCM in their applications. The 3rd-party application server sends data to an Android application on the device via the GCM server. • GCM Servers - The Google servers involved in taking messages from the 3rd- party application server and sending them to the device.
  • 7. GCM Architecture: Credentials Credentials • Sender ID - A project ID you acquire from the API console to identify an Android application that is permitted to send messages to the device. • Application ID - The Android application that is registering to receive messages. • Registration ID - An ID issued by the GCM servers to the Android application that allows it to receive messages. • Google User Account - For GCM to work, the mobile device must include at least one Google account if the device is running a version lower than Android 4.0.4. • 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.
  • 8. GCM: Implementation • 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. (we'll do it with php) • Receiving a Message - An Android application receives a message from a GCM server.
  • 9. GCM: Implementation Steps (1) • Goto https://code.google.com/apis/console • Create a project - Project_Name • Browser link has changed as https://code.google.com/apis/console/? pli=1#project:351708780651:services • it contains project id (94384365614 in this example) • We required that in our application as sender id.
  • 10. GCM: Implementation Steps (2) • 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.
  • 11. GCM: Implementation Steps (3) • In the main Google APIs Console page, select API Access. Now you can see there is API key if you use that key your application can receive messages from any server & if you want to restrict servers you can generate new server key using button there as “Create new server key…”.
  • 12. GCM: Implementation Steps (3.1) Now we have Sender ID and API KEY • Sender ID - 351708780651 • API KEY - AIzaSyBFhGpJswkvMxMTElfAQeMUskG13ii7s1Q
  • 13. GCM: Implementation Steps (4) • Create new Android Project • Copy the gcm.jar file from - SDK~PATH/extras/google/gcm/gcm-client/dist directory to your application classpath. As external jar.
  • 14. GCM: Implementation Steps (6) Permissions in Manifest • INTERNET – To make your app use internet services. <uses-permission android:name="android.permission.INTERNET" /> • ACCESS_NETWORK_STATE – To access network state (used to detect internet status) <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> • GET_ACCOUNTS – Required as GCM needs google account <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  • 15. GCM: Implementation Steps (6) Permissions in Manifest • WAKE_LOCK – Needed if your app need to wake your device when it sleeps <uses-permission android:name="android.permission.WAKE_LOCK" /> • VIBRATE – Needed if your support vibration when receiving notification Also add some broadcast receivers as mentioned below. <uses-permission android:name="android.permission.VIBRATE" />
  • 16. GCM: Implementation Steps (7) • Add GCM Receiver BroadcastReceiver that will receive intent from GCM Services and handle them To the custom Intent Services. <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <!-- Receives the registration id. --> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.androidexample.gcm" /> </intent-filter> </receiver>
  • 17. GCM: Implementation Steps (9) • Add GCMIntentService extending GCMBaseIntentService and add the service in Manifest <service android:name="com.androidexample.gcm.GCMIntentService" /> public class GCMIntentService extends GCMBaseIntentService {  /** * Method called on device registered **/ @Override protected void onRegistered(Context context, String registrationId) {  /** * Method called on device unregistred * */ @Override protected void onUnregistered(Context context, String registrationId) {
  • 18. GCM: Implementation Steps (9) • Add GCMIntentService extending GCMBaseIntentService and add the service in Manifest  /** * Method called on Receiving a new message from GCM server * */ @Override protected void onMessage(Context context, Intent intent) {  /** * Method called on receiving a deleted message * */ @Override protected void onDeletedMessages(Context context, int total) {
  • 19. GCM: Implementation Steps (10) • Register: // Make sure the device has the proper dependencies. GCMRegistrar.checkDevice(this); // Make sure the manifest permissions was properly set GCMRegistrar.checkManifest(this); // Get GCM registration id final String regId = GCMRegistrar.getRegistrationId(this); // Check if regid already presents if (regId.equals("")) { // Register with GCM GCMRegistrar.register(this, Config.GOOGLE_SENDER_ID); } else {
  • 20. GCM: Implementation Steps (10)  Register: // Device is already registered on GCM Server if (GCMRegistrar.isRegisteredOnServer(this)) { // Skips registration. Toast.makeText(getApplicationContext(), "Already registered with GCM Server", Toast.LENGTH_LONG).show(); }
  • 21. GCM: Implementation Steps (10) • Unregister: // Unregister Broadcast Receiver unregisterReceiver(mHandleMessageReceiver);
  • 22. GCM: Implementation Steps (11) • Receive Message /** * Method called on Receiving a new message from GCM server * */ @Override protected void onMessage(Context context, Intent intent) { if(aController == null) aController = (Controller) getApplicationContext(); Log.i(TAG, "Received message"); String message = intent.getExtras().getString("price"); aController.displayMessageOnScreen(context, message); // notifies user generateNotification(context, message); }
  • 23. GCM: Implementation Steps (12) • Send Message from Server //Sending Push Notification function send_push_notification($registatoin_ids, $message) { // Set POST variables $url = 'https://android.googleapis.com/gcm/send'; $fields = array( 'registration_ids' => $registatoin_ids, 'data' => $message, ); $headers = array( 'Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json' );