UWP:BackgroundTask打开App Mainpage

时间:2016-03-04 10:47:43

标签: win-universal-app background-task

是否可以通过我自己的后台任务打开我的应用程序?

当我在Windows通用平台上有一个backgroudtask时,我可以从那里开始或打开我的app.mainpage吗? 我的backgroundtask会定期检查剪贴板,如果它被点击,那么它应该打开我的应用程序。

这可以用于uwp还是uwp再次成为禁止使用的软件? 因此,任何解决方案或想法?

1 个答案:

答案 0 :(得分:0)

你可以通过祝酒来做到这一点。这是一个例子。

   var content =
        $@"
            <toast activationType='foreground' launch='args'>
                <visual>
                    <binding template='ToastGeneric'>
                        <text>Open app</text>
                        <text>Your clipboard is ready.Open app</text>
                    </binding>
                </visual>
                <actions>

                    <action content='ok' activationType='foreground' arguments='check'/>

                  <action activationType='system' arguments='dismiss' content='cancel' />

                </actions>
            </toast>";


        Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
        toastDOM.LoadXml(content);
        ToastNotification toast = new ToastNotification(toastDOM);
        var notifier = ToastNotificationManager.CreateToastNotifier();
        notifier.Show(toast);

然后,如果用户按下确定按钮,您必须进入App.xaml.cs并处理

 protected override void OnActivated(IActivatedEventArgs args)
    {
        if (args.Kind == ActivationKind.ToastNotification)
        {
            var toastArgs = args as ToastNotificationActivatedEventArgs;
            var arguments = toastArgs.Argument;

            if (arguments == "check")
            {
                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }
                rootFrame.Navigate(typeof(YOURPAGEHERE));
                Window.Current.Activate();
            }
        }
    }
相关问题