简体   繁体   English

Windows Phone 7 Toast通知,前台有应用程序

[英]Windows phone 7 Toast notification with app in foreground

Quick question. 快速提问。 I did this: 我这样做:

myChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myChannel_ShellToastNotificationReceived);

So if I receive a toast notification while the application is in the foreground the myChannel_ShellToastNotificationReceived function should be called. 因此,如果在应用程序处于前台时收到烤面包通知,则应调用myChannel_ShellToastNotificationReceived函数。 In that function I have: 在该功能中,我有:

void myChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
    Dispatcher.BeginInvoke(() =>
    {
       ApplicationTitle.Text = "Toast Notification Message Received";
    });
}

The problem is that the function is never called and the ApplicationTitle is never changed. 问题在于,函数永远不会被调用,ApplicationTitle永远不会改变。

Am I doing anything wrong? 我做错什么了吗?

I've found the problem...it seemed that the toast xml that was being sent was well enough formatted so the phone would receive it out of the app but not when it was inside it. 我发现了问题...似乎已发送的Toast xml格式正确,因此手机可以从应用程序中接收到它,但当它放在其中时却不会。 Wrote the xml by "hand" and didn't use xmlWriter and worked. 通过“手工”编写了xml,并且没有使用xmlWriter即可工作。

string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<wp:Notification xmlns:wp=\"WPNotification\">" +
           "<wp:Toast>" +
              "<wp:Text1>" + title + "</wp:Text1>" +
              "<wp:Text2>" + message + "</wp:Text2>" +
           "</wp:Toast>" +
        "</wp:Notification>";

您的频道是否已注册以接收通知?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM