Android : Cannot send push notification via Azure Mobile Service

on Sunday, August 3, 2014


I have setup a Mobile Service in Azure and connected it to my Android app. Through this app I am calling the Azure API to insert an object into a database table linked to the mobile service.


I have written the script that is executed before it gets inserted. That script is intended to send a push notification to another device.


Now the case is, the object gets inserted into table but no push notification is received. What could be wrong? How can i debug?


Here's my insert script:



function insert(message, user, request) {

//This is logic to get receiver device's handler
var receiverHandle;

var deviceTable = tables.getTable('devices');
deviceTable.where({
userId: item.receiver
}).read({
success: fillHandle
});


request.execute({
success: function() {
// Write to the response and then send the notification in the background
request.respond();
push.gcm.send(item.handle, item.message, {
success: function(response) {
console.log('Push notification sent: ', response);
}, error: function(error) {
console.log('Error sending push notification: ', error);
}
});
}
});

function fillHandle(results) {
receiverHandle = results[0].handle;
}


request.execute({
success: function() {
// Write to the response and then send the notification in the background
request.respond();
push.gcm.send(receiverHandle, "Hello! Push", {
success: function(response) {
console.log('Push notification sent: ', response);
}, error: function(error) {
console.log('Error sending push notification: ', error);
}
});
}
});

}

0 comments:

Post a Comment