2016-03-04 49 views
1

是否可以通过我自己的backgroundtask打开我的应用程序?UWP:BackgroundTask打开应用程序主页

当我在windows通用平台上有一个backgroudtask,我可以从那里启动或打开我的app.mainpage吗? 我的backgroundtask检查剪贴板期刊,如果它得到一个命中,那么它应该打开我的应用程序。

这个工作与uwp或uwp再次一个没有去软件? 因此有什么解决办法或想法?

回答

0

你可以通过干杯做到这一点。这是一个例子。

var content = 
     [email protected]" 
      <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); 

然后,如果用户按下OK按钮,你必须在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(); 
      } 
     } 
    } 
+1

感谢那个例子。 是不是可以从backgrountTask启动启动器()? –

相关问题