如何使用 url 在后台使用应用程序的主要 window 启动 UWP 应用程序

How to launch UWP app with app's main window in background using url

我想从另一个应用启动 UWP 应用。例如,我想使用启动协议(ms-people:、msnweather: 等)启动应用程序。我正在使用 API LaunchUriAsync。它正在启动应用程序。但是启动的新应用程序获得了焦点,它的主要 window 出现在我正在与之交互的应用程序之上(我从中启动了这个新应用程序)。 但是我想将这个新应用程序 window 保留在后台,让用户与原始应用程序进行交互。我怎么做? 谢谢

How to launch UWP app with app's main window in background using url

恐怕 LaunchUriAsync api 不包含使用 url 在后台启动应用程序主要 window 的选项。但是我们有一个解决方法,如果应用程序是使用 uri 启动的,则手动将启动的应用程序推送到后台。

OnActivated 事件处理程序接收所有激活事件。 Kind 属性 表示激活事件的类型。所以你可以在下面最小化目标应用程序

protected override void OnActivated(IActivatedEventArgs args)
  {
      if (args.Kind == ActivationKind.Protocol)
      {
         ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
         // TODO: Handle URI activation
         // The received URI is eventArgs.Uri.AbsoluteUri
      }
   }

要最小化应用程序,请参考此