4

我们正在学习本教程:操作方法:适用于 Android 的 Windows Azure 通知中心(Android 应用程序)

按照指南中的描述构建通知有效负载时,一切正常。那是:

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

但是,我们希望扩展模板以在有效负载中使用多个自定义属性。就像是:

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

后端通过以下方式提供属性值:

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

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

从移动应用程序在通知中心注册模板时,我们收到以下错误:

“提供的通知负载无效”

  • 模板中可以使用多个属性吗?
  • 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

4

2 回答 2

6

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");
于 2013-10-08T15:36:34.617 回答
0

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");
于 2017-06-03T05:52:13.070 回答