Question

We're following this tutorial: How To: Windows Azure Notification Hubs (Android Apps) for Android.

Everything works fine when structuring the notification payload as described in the guide. That is:

{
    "data": {
        "msg": "$(property1)"
    }
}

However, we'd like to extend the template to use more than one custom property in the payload. Something like:

{
  "data": {
    "msg": {
        "message": "$(property1)",
        "sender": "$(property2)"
    }
  }
}

where the back-end supplies the property values via:

Dictionary<string, string> templateValues = new Dictionary<string, string>
    {
        { "property1", "Hello world" },
        { "property2", "foo" }
    };

NotificationOutcome notificationOutcome = await Hub.SendTemplateNotificationAsync(templateValues, "test");

When registering the template in the notification hub from the mobile app we receive the following error:

"Supplied notification payload is invalid"

  • Can several properties be used in the template?
  • Should we send the property value (from the back-end) as a JSON (or other structure) string instead? What is the preferred approach? We will use the template on multiple platforms (iOS, Android)

Thanks in advance

Was it helpful?

Solution

The payload is invalid because GCM does not support nested object in the data member. You can send the message with two property by registering for the following template:

{
   "data": {
      "message": "$(property1)",
      "sender": "$(property2)"
   }
}

In you Android receiver then you can retrieve your property with

intent.getStringExtra("property1");

OTHER TIPS

In my tests, you can add your parameters:

Template:

{
   "data": {
      "message": "$(property1)",
      "args": "$(property2)",
      "myargs": "$(property3)",
   }
}

Data:

{  
    "property1":"Jonh",    
    "property2":"1,1",
    "property3":"0",
}

Results:

intent.Extras.GetString("message");
intent.Extras.GetString("args");
intent.Extras.GetString("myargs");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top