Windows phone 7 Toast notification with app in foreground

梦想与她 提交于 2020-01-03 05:11:19

问题


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. 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.

Am I doing anything wrong?


回答1:


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. Wrote the xml by "hand" and didn't use xmlWriter and worked.

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>";


来源:https://stackoverflow.com/questions/8305020/windows-phone-7-toast-notification-with-app-in-foreground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!