Push Notification inside ScheduledAgent in Windows Phone 8

只谈情不闲聊 提交于 2019-12-11 11:46:23

问题


I would like to achieve a similar task, in which I want to re-establish my push notification channel using background agent. Is it possible?

I am using the following code inside my ScheduledAgent, but its not working. If I cannot access the channel APIs, is there any alternative to that? How have popular apps like whats-app and others been able to achieve this? Please help me.

Can you advise me an alternative? How can I update my user that there is something new for him from my server without using this approach?

    protected override void OnInvoke(ScheduledTask task)
    {
        //TODO: Add code to perform your task in background
        HttpNotificationChannel pushChannel = HttpNotificationChannel.Find("HikeApp");
        if (pushChannel == null)
        {
            pushChannel = new HttpNotificationChannel("HikeApp");

            // Register for all the events before attempting to open the channel.
            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.Open();
            pushChannel.BindToShellTile();
            pushChannel.BindToShellToast();
        }
        else
        {
            // the channel was already open, so just register for all the events.
            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
        }

        #if DEBUG_AGENT
        ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(1));
        #endif

        NotifyComplete();
    }

回答1:


As per the list of Unsupported APIs in Background Agents, it is not possible to do anything in the Microsoft.Phone.Notification namespace, which includes everything to do with push notifications, from a scheduled agent.



来源:https://stackoverflow.com/questions/16670677/push-notification-inside-scheduledagent-in-windows-phone-8

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