0

如何格式化推送通知,以便当它显示在状态栏上时,它可以利用本地通知的结构 - 显示文本并隐藏数据?通过Android的状态栏处理推送通知

行为:移动应用程序未运行时,会在设备状态栏上显示推送通知。当用户点击状态栏上的通知时,通知消失,应用程序打开。虽然这是可以接受的行为,但发起的推送通知未格式化,用户无法在状态栏上查看。如何将推送通知格式化以便与状态栏(本地通知)查看更兼容?换句话说,隐藏数据但显示用户可读的文本?

插件:

  • 推送通知:PhoneGap的-插件推动本地通知
  • 本地通知:de.appplant.cordova.plugin.local通知

的.Net C#应用程序服务代码:

string xml = "<ACTION>Add</ACTION>" + 
      "<UserId>" + ut.UserId + " </UserId>"; 
Dictionary<string, string> templateParams = new Dictionary<string, string>(); 
templateParams["messageParam"] = xml; 
try 
{ 
    NotificationOutcome result = await 
     hub.SendTemplateNotificationAsync(templateParams, tagId); 
    config.Services.GetTraceWriter().Info(result.State.ToString()); 
    return result; 
} 

以下是我的移动应用代码:

cordova.plugins.notification.local.on("click", function (notification) { 
    // Notification.text - contains whatever is in messageParam 
    // Notification.data - How do I format the app service code so that the 
    //      xml shows up in Notification.data? 
}); 

感谢您的任何帮助。

+0

我可以将xml转换为对象。 C#如何将字符串转换为JavaScript对象?另外,如何格式化Web服务的templateParams? – Mike

回答

0

下面是我的解决办法...

服务器端:

Dictionary<string, string> templateParams = new Dictionary<string, string>(); 
templateParams["messageParam"] = xmlNotification; 
templateParams["titleParam"] = "testTitle"; 
templateParams["dataParam"] = "this is some data"; 

NotificationOutcome result = await 
    hub.SendTemplateNotificationAsync(templateParams, tagId); 
config.Services.GetTraceWriter().Info(result.State.ToString()); 

客户端注册:

AzureDbSvc.client.push.register('gcm', handle, { 
    mytemplate: { body: { data: { message: "{$(messageParam)}", title: "{$(titleParam)}", 
     data: "{$(dataParam)}" } }, tags: arrTags } 

客户端通知处理器:

pushRegistration.on('notification', function (data) { 
     ... 
    }); 

谢谢t Ø杰夫·桑德斯提供以下资料...

内容:

Debugger Quickwatch Window