2
votes

I am using Microsoft azure notification hub for push notification in android. I am able to send notification through nodejs server code. Device get notification from nodejs server.

Problem :- but when i use notification hub it the notification never comes through to the device even though the Notification Hub returns a success code.

Procedure I follow for notification hub.

Step -1 :- Register gcmTokenId to notification hub which i got from my device at a first time registration.

notificationHubService.gcm.createNativeRegistration(gcmToken, tags, function(error){    
          if(error)
          {
            res.type('application/json'); // set content-type
            res.send(error); // send text response
          }
          else
          {
            res.type('application/json'); // set content-type
            res.send('Registered Successfully!'); // send text response
          }
        });

Here are the registration details:-

{
ETag: "1"
ExpirationTime: "2014-09-08T06:33:55.906Z"
RegistrationId: "286469132885875691584-1648906343295271447-3"
Tags: "raj"
GcmRegistrationId: "APA91bF6E2U4*********"
_: {
ContentRootElement: "GcmRegistrationDescription"
id: "id"
title: "2864691328694691584-1648906343295271447-3"
published: "2014-06-10T07:04:30Z"
updated: "2014-06-10T07:04:30Z"
link: ""
}-
}

Step -2 :- Send Notification to hub using following function.

notificationHubService.gcm.send(
        null,
        {
            data: { message: 'Here is a message' }
        },
        function (error,response) {
            if (!error) {
                //message send successfully
                res.type('application/json'); // set content-type
        res.send(response);
            }
        });

Following are the response code i got from notification hub.

{
isSuccessful: true
statusCode: 201
body: ""
headers: {
transfer-encoding: "chunked"
content-type: "application/xml; charset=utf-8"
server: "Microsoft-HTTPAPI/2.0"
date: "Tue, 10 Jun 2014 07:07:32 GMT"
}-
}

Settings i did in notification hub:

  1. I add google api key in "google cloud messaging settings".

Please guide me to solve this issue.

1

1 Answers

0
votes

It appears that when you registered, you supplied "raj" as the tag.

{
ETag: "1"
ExpirationTime: "2014-09-08T06:33:55.906Z"
RegistrationId: "286469132885875691584-1648906343295271447-3"
Tags: "raj" <<== HERE
GcmRegistrationId: "APA91bF6E2U4*********"
_: {
ContentRootElement: "GcmRegistrationDescription"
id: "id"
title: "2864691328694691584-1648906343295271447-3"
published: "2014-06-10T07:04:30Z"
updated: "2014-06-10T07:04:30Z"
link: ""
}-
}

A tag is like a subscription topic -- it is a filter.

You seem to be using the Node.js NotificationHubService.

Refer to http://dl.windowsazure.com/nodedocs/GcmService.html. The first parameter is tags, but in your code, you provided a null:

notificationHubService.gcm.send(
    null,   // <-- HERE
    {
        data: { message: 'Here is a message' }
    },

Since null won't match the tag "raj", then Notification Hubs won't deliver this message to any device that is registered to listen only for messages that have the tag "raj".

You should either set the tag to "raj" in the send() method call, or remove that tag from the call to the createNativeRegistration() method.