wp8:Handle Toast notification when application is in backgroung

时光总嘲笑我的痴心妄想 提交于 2019-12-23 04:28:55

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17317959/wp8handle-toast-notification-when-application-is-in-backgroung

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