Question

I have a mobile service in azure and an android application. I want to send push notification on user device who is registering it self. I got success on sending notifications through gcm but it is broadcasting the notifications on all devices. Please help me in this regard.

for sending notification I have customized insert query in azure but it is broadcasting the notifications. I have no idea how to send it in specific device.

my insert query is-

function insert(item, user, request) {
      var payload = '{"data":{"message" : "Hello from Mobile Services!"}}';
      request.execute({
           success: function() {
          // If the insert succeeds, send a notification.
             push.gcm.send(null, payload, {
             success: function(pushResponse) {
             console.log("Sent push:", pushResponse, payload);
             request.respond();
            },              
        error: function (pushResponse) {
            console.log("Error Sending push:", pushResponse);
            request.respond(500, { error: pushResponse });
            }
        });
    },
     error: function(err) {
     console.log("request.execute error", err)
     request.respond();
     }
 });
}
Was it helpful?

Solution

The first parameter to your call to push.gcm.send is null. This tells the push engine to push to any device that has registered to your service for GCM push. You can change this by either passing in the registration ID of the specific device you want to push to or look at how Notification Hubs work with Tags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top