wp8:Handle Toast notification when application is

2019-06-08 07:35发布

While my app is running I can receive toast notification,on ShellToastNotificationReceived(object sender, NotificationEventArgs e) event handler as keys in e.Collection.

If my app is not running and a toast notification arrives, a toast is displayed but how i can i handle this notification?

I mean which event is fire when my application is not running and notification arrives.

I know background agent but its not fulfill my requirement

Thanks.

2条回答
放荡不羁爱自由
2楼-- · 2019-06-08 07:56

yes we can handle the toast notification. once the user clicks on toast notification we can send a request to our web service and do our job.

what happens when an user clicks on toast notification is it will redirect to the application launching event in App.Xaml.cs page. in that event depending upon the toast content you can proceed to the next step.

hope this helps.

still if you didn't get it done, just drop a mail to me

happy coding.

查看更多
萌系小妹纸
3楼-- · 2019-06-08 07:58

Windows Phone platform is responsible to handle Push Notifications and developers don't have a direct access for notification handling when an app is not running. That means you can't do any background logic after Toast is received. But when Toast message contains <wp:Param> value with an Uri to a specific app page then user will be redirected to this page, if user taps a Toast popup. So, you can do specific job after user tapped a Toast popup. To accomplish it, you need add an parameter to Uri, for example /YourPage?IsToast=true and override OnNavigatedTo method of the page to run your business logic:

 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (NavigationContext.QueryString.ContainsKey("IsToast"))
            {
                //do your business here
            }
    }

For other cases you need to use a background worker.

查看更多
登录 后发表回答