Google Cloud Messaging (GCM) in Node.js
Introduction
GCM (Google Cloud Messaging) is a service provides by google that is used to send data to android device. It is free service from google that helps to send data from servers to android applications.
How to get Google APIs Key.
1. Create a new project from Google APIs Console page.
2. After creating project note down project id from url. Later it will be used as a sender id.
3. After that click on Services.
4. Once you are done, Click on API Access and write down the API Key. This key will be used for sending request to GCM Server.
How to use GCM service in our server side.
Install: npm install android-gcm
Simplest Code :
var gcm = equire('android-gcm');
var gcmObject = new gcm.AndroidGcm('API Key'); //get from Google APIs Console page.
var message = new gcm.Message({
registration_ids: ['device tokens1','device tokens2'],
data: {
title: 'message title here',
message: 'your message here'
}
});
gcmObject.send(message, function(err,response){
callback(err,response);
});
});
Thanks
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Samser Alam
Samser is a bright java developer and have knowledge of Core Java, J2EE, C , C++. He can work over Netbeans and myeclipse. and he loves to play cricket.