简体   繁体   中英

How can I receive toast for my app?

I've followed Jeff's tutorial and implemented push inside my application.

HttpNotificationChannel channel;

void GetPushChannel()
{
    channel = new HttpNotificationChannel("BLANKENSOFT_" + DateTime.Now.Ticks.ToString());
    channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
    channel.Open();
}

void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
    Dispatcher.BeginInvoke(delegate
    {
        URIBlock.Text = channel.ChannelUri.ToString();
    });
}

So I now can get and handle push notifications while I'm in my application. But what when my app is closed and I want to show a toast that something happened?

I thought of a ScheduledTaskAgent, but they are limited by the time they are active... what If a notification is sent when the agent isnt running? Or does it not matter?

I thought of implementing the very same function above in the ScheduledTaskAgent.

You can refer to the sample http://code.msdn.microsoft.com/wpapps/Toast-Notification-Sample-fb20ae13 . When the app is closed and notification is sent from server end, it will be received on device, no need for any ScheduledTaskAgent or background process. The payload for WP pushnotification looks like:

<?xml version=\1.0\ encoding=\utf-8\?>
<wp:Notification xmlns:wp=\WPNotification\>
  <wp:Toast>
    <wp:Text1>Title of application</wp:Text1>
    <wp:Text2>Subtitle for application</wp:Text2>
    <wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param> //supported from WP7.1 
  </wp:Toast>
</wp:Notification>

In the payload is included from WP7.1 and it is used to navigate user to the specific page at the time toast notification is received when application is closed. Also if you want to show any custom message when application is closed and toast arrives, navigate it to a specific page and show a message box with your custom message.

This is what I thought you wanted to know, If not let me know. Thanks

添加

pushChannel.BindToShellToast();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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