通过 Android 的状态栏处理推送通知

Handling Push Notifications via Android's Status Bar

如何设置推送通知的格式,以便在状态栏上显示时可以利用本地通知的结构——显示文本并隐藏数据?

行为:当移动应用未运行时,推送通知显示在设备的状态栏上 运行。当用户单击状态栏上的通知时,通知消失,应用程序打开。尽管这是可以接受的行为,但原始推送通知的格式并未设置为用户无法在状态栏上查看。如何格式化推送通知,使其更兼容状态栏(本地通知)查看?换句话说,隐藏数据但显示用户可读的文本?

插件:

.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?
});

感谢您的帮助。

下面是我的解决方案...

服务器端:

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) {
        ...
    });

感谢 Jeff Sanders 提供以下文档...

运行 时的数据内容: