【问题标题】:UWP: BackgroundTask open App MainpageUWP:BackgroundTask 打开应用主页
【发布时间】:2016-03-04 10:47:43
【问题描述】:

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

当我在 windows 通用平台中有一个背景任务时,我可以从那里启动或打开我的 app.mainpage 吗? 我的 backgroundtask 会定期检查剪贴板,如果它被点击,那么它应该打开我的应用程序。

这是否适用于 uwp 或者 uwp 又是一个禁止使用的软件? 因此有什么解决方案或想法?

【问题讨论】:

    标签: win-universal-app background-task


    【解决方案1】:

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

       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();
                }
            }
        }
    

    【讨论】:

    • 感谢这个例子。是不是可以从backgrountTask启动launcher()?
    猜你喜欢
    • 2020-09-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 2019-02-13
    • 2012-10-21
    • 2020-06-28
    • 2011-11-19
    相关资源
    最近更新 更多