private void GetActivationInfo() { AppActivationArguments args = AppInstance.GetCurrent().GetActivatedEventArgs(); ExtendedActivationKind kind = args.Kind; OutputMessage($"ActivationKind: {kind}"); if (kind == ExtendedActivationKind.Launch) { ILaunchActivatedEventArgs launchArgs = args.Data as ILaunchActivatedEventArgs; if (launchArgs != null) { string argString = launchArgs.Arguments; string[] argStrings = argString.Split(); foreach (string arg in argStrings) { if (!string.IsNullOrWhiteSpace(arg)) { OutputMessage(arg); } } } } else if (kind == ExtendedActivationKind.File) { IFileActivatedEventArgs fileArgs = args.Data as IFileActivatedEventArgs; if (fileArgs != null) { IStorageItem file = fileArgs.Files.FirstOrDefault(); OutputMessage(file.Name); } } else if (kind == ExtendedActivationKind.Protocol) { IProtocolActivatedEventArgs protocolArgs = args.Data as IProtocolActivatedEventArgs; if (protocolArgs != null) { Uri uri = protocolArgs.Uri; OutputMessage(uri.AbsoluteUri); } } else if (kind == ExtendedActivationKind.StartupTask) { IStartupTaskActivatedEventArgs startupArgs = args.Data as IStartupTaskActivatedEventArgs; if (startupArgs != null) { OutputMessage(startupArgs.TaskId); } } }
protected override void OnActivated(IActivatedEventArgs args) { XboxGameBarWidgetActivatedEventArgs widgetArgs = null; if (args.Kind == ActivationKind.Protocol) { IProtocolActivatedEventArgs protocolArgs = args as IProtocolActivatedEventArgs; string scheme = protocolArgs.Uri.Scheme; if (scheme.Equals("ms-gamebarwidget")) { widgetArgs = args as XboxGameBarWidgetActivatedEventArgs; } } if (widgetArgs != null) { // // Activation Notes: // // If IsLaunchActivation is true, this is Game Bar launching a new instance // of our widget. This means we have a NEW CoreWindow with corresponding UI // dispatcher, and we MUST create and hold onto a new XboxGameBarWidget. // // Otherwise this is a subsequent activation coming from Game Bar. We MUST // continue to hold the XboxGameBarWidget created during initial activation // and ignore this repeat activation, or just observe the URI command here and act // accordingly. It is ok to perform a navigate on the root frame to switch // views/pages if needed. Game Bar lets us control the URI for sending widget to // widget commands or receiving a command from another non-widget process. // // Important Cleanup Notes: // When our widget is closed--by Game Bar or us calling XboxGameBarWidget.Close()-, // the CoreWindow will get a closed event. We can register for Window.Closed // event to know when our partucular widget has shutdown, and cleanup accordingly. // // NOTE: If a widget's CoreWindow is the LAST CoreWindow being closed for the process // then we won't get the Window.Closed event. However, we will get the OnSuspending // call and can use that for cleanup. // if (widgetArgs.IsLaunchActivation) { Frame rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; Window.Current.Content = rootFrame; if (widgetArgs.AppExtensionId == "MainPage") { widget1 = new XboxGameBarWidget( widgetArgs, Window.Current.CoreWindow, rootFrame); rootFrame.Navigate(typeof(ListsView), widget1); Window.Current.Closed += Widget1Window_Closed; } else if (widgetArgs.AppExtensionId == "Settings") { widget1Settings = new XboxGameBarWidget( widgetArgs, Window.Current.CoreWindow, rootFrame); rootFrame.Navigate(typeof(SettingsView)); Window.Current.Closed += Widget1SettingsWindow_Closed; } //Window.Current.Closed += Widget1Window_Closed; Window.Current.Activate(); } else { // You can perform whatever behavior you need based on the URI payload. } } }