Blog

  • Step 1: First, install android-gcm package in your node application using the commmand:

       npm install android-gcm 
            

    Step 2: write the code given below

    var gcm = require('android-gcm');
    
    // Max devices per request
    var batchLimit = 1000;
    var tokenBatches = [];
    var deviceTokens=['x', 'y', 'z','a','b','c','d'];
    
    for (var start = 0; start < deviceTokens.length; start += batchLimit) {
        var slicedTokens = deviceTokens.splice(start, start + batchLimit);
        tokenBatches.push(slicedTokens);
    }
    
    async.each(tokenBatches, function (batch, next) {
        var gcmObject = new gcm.AndroidGcm('API_KEY');
        var message = new gcm.Message({
            registration_ids: batch,
            data: {
                message:'Hello'
            }
        });
        gcmObject.send(message, function (err, response) {
                next(err,response);
        });
    }, function (err) {
        if (err) {
            console.log('Error in sending notification'', err);
        }
    }); 
            

    THANKS

Tags: android

View All PostsLeave a Comment
comments powered by Disqus

Mobile Applications

Video Content

Bigdata & NoSQL

SaaS Applications

Miscellaneous

Archives


Alexa Certified Site Stats for www.oodlestechnologies.com