Sunday, 15 September 2013

android - node-gcm sending successfully but I do not know how to get the data from the client side -



android - node-gcm sending successfully but I do not know how to get the data from the client side -

so sending on server side so, using node-gcm (https://github.com/toothlessgear/node-gcm):

var gcm = require('node-gcm'); var message = new gcm.message({ collapsekey: 'demo', delaywhileidle: true, timetolive: 3, data: { type: 'pong', message: 'hello android!' } }); var sender = new gcm.sender(myapikey); var registrationids = [adoc.registrationid]; sender.send(message, registrationids, 4, function (err, result) { console.log(result); });

and on client side, in broadcastreceiver, logcat message printing , receive notification, extras (from intent.getstringextra("data") null. how properly? cannot find how anywhere. registration case works perfectly.

@override protected void onhandleintent(intent intent) { string action = intent.getaction(); log.i(tag, "gcm received"); switch(action){ case gcm.action_registration: string registrationid = intent.getstringextra(gcm.key_reg_id); log.i(tag, "action received: registration: " + registrationid); ... break; case gcm.action_receive: string extras = intent.getstringextra("data"); log.v(tag, "" + extras); ... ...

extras consistantly null

through experimentation, have solved problem. instead of accesssing info object directly, node-gcm adds key-value pairs intent's extras directly:

wrong:

// returns null string datajson = intent.getstringextra("data");

right:

// returns "pong" string type = intent.getstringextra("type");

android node.js google-cloud-messaging

No comments:

Post a Comment