1
所以我在服務器端發送像這樣得到的數據,利用節點-GCM
(https://github.com/ToothlessGear/node-gcm):節點-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);
});
然後在客戶端,在我的BroadcastReceiver中,我得到了Logcat消息打印和接收通知,但extras(來自intent.getStringExtra(「data」))爲null。如何正確獲取它?我找不到在任何地方都可以做到這一點。註冊案例完美無瑕。
@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);
...
...
臨時演員陣容是空的