/// <inheritdoc/> public string TrackLaunch(string launchArgs) { StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch(launchArgs); return(originalArgs); }
protected override async void OnActivated(IActivatedEventArgs args) { await ActivationService.ActivateAsync(args); //Comunicare a Dev Center che la tua app è stata avviata base.OnActivated(args); if (args is ToastNotificationActivatedEventArgs) { var toastActivationArgs = args as ToastNotificationActivatedEventArgs; StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch( toastActivationArgs.Argument); // Use the originalArgs variable to access the original arguments // that were passed to the app. } //AVVIO APP CON WINDOWS string payload = string.Empty; if (args.Kind == ActivationKind.StartupTask) { var startupArgs = args as StartupTaskActivatedEventArgs; payload = ActivationKind.StartupTask.ToString(); } NavigationService.Navigate(typeof(HomePagePage), payload); Window.Current.Activate(); }
private async void InitOnlineServiceAsync() { try { var tileUpdater = Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication(); IReadOnlyList <ScheduledTileNotification> plannedUpdated = tileUpdater.GetScheduledTileNotifications(); tileUpdater.Clear(); for (int i = 0, len = plannedUpdated.Count; i < len; i++) { // The itemId value is the unique ScheduledTileNotification.Id assigned to the notification when it was created. tileUpdater.RemoveFromSchedule(plannedUpdated[i]); } //var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); //var hub = new NotificationHub("jpdictHub", "Endpoint=sb://jpdictnamespace.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=b7P3q6gSzqgLDiCIFOv8q62J7EUft7RQr3F6TEIfXMg="); //var result = await hub.RegisterNativeAsync(channel.Uri); //AppCenter.Configure("de248288-41ba-4ca6-b857-4bfaa6758c63"); StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); AppCenter.Start("de248288-41ba-4ca6-b857-4bfaa6758c63", typeof(Analytics), typeof(Crashes), typeof(Push)); } catch { Debug.WriteLine("Registration failed"); } //// Displays the registration ID so you know it was successful //if (result.RegistrationId != null) //{ // var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); // dialog.Commands.Add(new UICommand("OK")); // await dialog.ShowAsync(); //} }
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args) { var engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); if (args.Kind == ActivationKind.ToastNotification) { var toastArgs = args as ToastNotificationActivatedEventArgs; var originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch(toastArgs?.Argument); if (originalArgs != null && originalArgs.Contains("id")) { Debug.WriteLine($"OnActivated ToastNotification argument: {originalArgs}"); NavigationService.Navigate(typeof(HomePage), originalArgs); } else { NavigationService.Navigate(typeof(HomePage)); } } else { NavigationService.Navigate(typeof(HomePage)); } }
private async Task RegisterCommunicationChannel() { if (!Settings.DisableNotifications) { StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); engagementManager.RegisterNotificationChannelAsync(); } }
private async void Example3() { //<UnregisterNotificationChannelAsync> StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.UnregisterNotificationChannelAsync(); //</UnregisterNotificationChannelAsync> }
private async void Example1() { //<RegisterNotificationChannelAsync1> StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); //</RegisterNotificationChannelAsync1> }
private async void InitNotificationsAsync() { PushNotificationChannel pnc = null; Registration result = null; //try //{ // var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); // var hub = new NotificationHub("wnsTestHub", "Endpoint=sb://wnstest.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=xxxxxxxxIM9oJOAEpekrKLCYGNnHtpjEULOLv01G0Sbi8="); // var res1 = await hub.RegisterNativeAsync(channel.Uri); // pnc = channel; // result = res1; //} //catch (Exception ex) //{ // Crashes.TrackError(ex); //} #if DEBUG // Displays the registration ID so you know it was successful //if (result != null) // if (result.RegistrationId != null) // { // var dialog = new MessageDialog("Notification Hub Registration successful: " + result.RegistrationId); // dialog.Commands.Add(new UICommand("OK")); // await dialog.ShowAsync(); // } #endif StoreServicesNotificationChannelRegistrationResult res = null; try { // Register with Partner Center engagement notifications StoreServicesNotificationChannelParameters parameters = new StoreServicesNotificationChannelParameters(); if (pnc != null) { parameters.CustomNotificationChannelUri = pnc.Uri; } StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); res = await engagementManager.RegisterNotificationChannelAsync(parameters); } catch (Exception ex) { Crashes.TrackError(ex); } #if DEBUG // Displays the registration ID so you know it was successful if (res.ErrorCode == StoreServicesEngagementErrorCode.None) { var dialog = new MessageDialog("Engagement Notificaiton Registration successful: " + res.ErrorMessage); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } #endif }
protected override void OnActivated(IActivatedEventArgs args) { if (args is ToastNotificationActivatedEventArgs) { Analytics.TrackEvent("User Clicked Notification"); var toastActivationArgs = args as ToastNotificationActivatedEventArgs; StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch( toastActivationArgs.Argument); // Use the originalArgs variable to access the original arguments // that were passed to the app. } Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } var navigationDestination = typeof(MainPage); if (rootFrame.Content == null) { rootFrame.Navigate(navigationDestination); } if (args.Kind == ActivationKind.Protocol) { ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs; var parser = DeepLinkParser.Create(args); if (parser.ContainsKey("promo")) { if (parser["promo"] == "winterwonderland") { navigationDestination = typeof(PromoPage); rootFrame.Navigate(navigationDestination); } } } // Ensure the current window is active Window.Current.Activate(); }
private static async Task SetupPushNotifications() { var engagementManager = StoreServicesEngagementManager.GetDefault(); if (engagementManager != null) { await engagementManager.RegisterNotificationChannelAsync(); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); FindDeviceD(); //FindDeviceLe(); }
public static IAsyncOperation <int> Init() { return(Task.Run(async() => { StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); var res = await engagementManager.RegisterNotificationChannelAsync(); return (int)res.ErrorCode; }).AsAsyncOperation()); }
private void RegisterToastNotification(IActivatedEventArgs args) { if (args is ToastNotificationActivatedEventArgs) { var toastActivationArgs = args as ToastNotificationActivatedEventArgs; StoreServicesEngagementManager engagementManagerForLaunch = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManagerForLaunch.ParseArgumentsAndTrackAppLaunch(toastActivationArgs.Argument); } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; AppCenter.Start("d822e171-9f7e-4efb-866a-2e53a641aa7d", typeof(Analytics), typeof(Crashes), typeof(Push)); StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); engagementManager.RegisterNotificationChannelAsync(); }
public async Task InitializeAsync() { try { var engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); } catch (Exception) { } }
protected override async Task HandleInternalAsync(ToastNotificationActivatedEventArgs args) { var toastActivationArgs = args as ToastNotificationActivatedEventArgs; StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch(toastActivationArgs.Argument); //// Use the originalArgs variable to access the original arguments passed to the app. await Task.CompletedTask; }
public async Task InitializeAsync() { try { var engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); } catch (Exception) { // TODO WTS: Channel registration call can fail, please handle exceptions as appropriate to your scenario. } }
protected override async void OnLaunched(LaunchActivatedEventArgs args) { if (!args.PrelaunchActivated) { await ActivationService.ActivateAsync(args); } //Per ricevere nell'app notifiche che invio dal Dashboard https://docs.microsoft.com/it-it/windows/uwp/publish/send-push-notifications-to-your-apps-customers //Eseguire la registrazione per le notifiche push StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); }
private async void Example2() { //<RegisterNotificationChannelAsync2> StoreServicesNotificationChannelParameters parameters = new StoreServicesNotificationChannelParameters(); parameters.CustomNotificationChannelUri = "Assign your channel URI here"; StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(parameters); //</RegisterNotificationChannelAsync2> }
public void Run(IBackgroundTaskInstance taskInstance) { var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; if (details != null) { StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch(details.Argument); // Use the originalArgs variable to access the original arguments // that were passed to the app. } }
/// <summary> /// Register App To recieve notifications from Windows Store /// https://docs.microsoft.com/en-us/windows/uwp/monetize/configure-your-app-to-receive-dev-center-notifications /// </summary> private async Task RegisterAppForStoreNotifications() { var localSettingsValues = ApplicationData.Current.LocalSettings.Values; if (!(localSettingsValues.ContainsKey("IsStoreEngagementEnabled"))) { localSettingsValues["IsStoreEngagementEnabled"] = true; } if ((bool)localSettingsValues["IsStoreEngagementEnabled"]) { var engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); } }
protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args) { base.OnBackgroundActivated(args); // ReSharper disable once ConvertIfStatementToSwitchStatement if (args.TaskInstance.TriggerDetails is ToastNotificationActionTriggerDetail toastActivationArgs) { var engagementManager = StoreServicesEngagementManager.GetDefault(); var originalArgs = engagementManager?.ParseArgumentsAndTrackAppLaunch( toastActivationArgs.Argument); // Use the originalArgs variable to access the original arguments // that were passed to the app. } }
protected override void OnActivated(IActivatedEventArgs args) { base.OnActivated(args); if (args is ToastNotificationActivatedEventArgs) { var toastActivationArgs = args as ToastNotificationActivatedEventArgs; StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); string originalArgs = engagementManager.ParseArgumentsAndTrackAppLaunch( toastActivationArgs.Argument); // Use the originalArgs variable to access the original arguments // that were passed to the app. } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { var engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); var pane = InputPane.GetForCurrentView(); pane.Showing += Pane_Showing; pane.Hiding += Pane_Hiding; var navigation = SystemNavigationManager.GetForCurrentView(); navigation.BackRequested += Navigation_BackRequested; try { var vault = new PasswordVault(); var result = vault.FindAllByResource(Constants.TOKEN_IDENTIFIER).FirstOrDefault(t => t.UserName == "Default"); if (result != null) { connectingOverlay.Visibility = Visibility.Visible; connectingOverlay.Opacity = 1; connectingScale.ScaleX = 1; connectingScale.ScaleY = 1; mainScale.ScaleX = 0.85; mainScale.ScaleY = 0.85; IsOverlayShown = true; connectingProgress.IsIndeterminate = true; result.RetrievePassword(); await App.LoginAsync(result.Password, OnFirstDiscordReady, App.LoginError, false); } else { rootFrame.Navigate(typeof(LoginPage)); await ClearJumpListAsync(); } } catch { rootFrame.Navigate(typeof(LoginPage)); await ClearJumpListAsync(); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { PrepareAppWindow(); // Register for Targeted notifications StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); _ = engagementManager.RegisterNotificationChannelAsync(); Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); } }
private async void BroadcastToggle_OnToggled(object sender, RoutedEventArgs e) { if (IsFirstTimeOpened) { IsFirstTimeOpened = false; return; } var engagementManager = StoreServicesEngagementManager.GetDefault(); if (BroadcastToggle.IsOn) { await engagementManager.RegisterNotificationChannelAsync(); ApplicationData.Current.LocalSettings.Values["IsStoreEngagementEnabled"] = true; } else { await engagementManager.UnregisterNotificationChannelAsync(); ApplicationData.Current.LocalSettings.Values["IsStoreEngagementEnabled"] = false; } }
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args) { // await Task.Delay(4); try { StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"HomeControlCommands.xml"); await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile); } catch { // System.Diagnostics.Debug.WriteLine("There was an error registering the Voice Command Definitions", ex); } StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); // TODO: add your long-running task here // await Windows.Storage.ApplicationData.Current.ClearAsync(); IPropertySet roamingProperties = ApplicationData.Current.RoamingSettings.Values; if (roamingProperties.ContainsKey("HasBeenHereBefore")) { // The normal case await NavigationService.NavigateAsync(typeof(Views.MainPage)); } else { // The first-time case Shell.HamburgerMenu.IsFullScreen = true; await NavigationService.NavigateAsync(typeof(Views.HelpPage)); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["oneshot"] = "true"; roamingProperties["HasBeenHereBefore"] = bool.TrueString; // Doesn't really matter what } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected async override void OnLaunched(LaunchActivatedEventArgs e) { bool canEnablePrelaunch = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch"); if (e != null) { if (e.PreviousExecutionState == ApplicationExecutionState.Running) { Window.Current.Activate(); return; } } Helper.ChangeAppMinSize(540, 744); try { //StoreServicesNotificationChannelParameters parameters = // new StoreServicesNotificationChannelParameters(); //parameters.CustomNotificationChannelUri = "Assign your channel URI here"; //StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); //await engagementManager.RegisterNotificationChannelAsync(parameters); await Helper.RunInBackground(async() => { StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); await engagementManager.RegisterNotificationChannelAsync(); }); } catch { // } // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (!(Window.Current.Content is Frame rootFrame)) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = CreateRootFrame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } if (e.PreviousExecutionState != ApplicationExecutionState.Running) { bool loadState = (e.PreviousExecutionState == ApplicationExecutionState.Terminated); SplashView extendedSplash = new SplashView(e.SplashScreen, loadState); rootFrame.Content = extendedSplash; //rootFrame.Content = new Views.BlankPage1(); Window.Current.Content = rootFrame; } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (canEnablePrelaunch) { TryEnablePrelaunch(); } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected async override void OnLaunched(LaunchActivatedEventArgs e) { InstallCommandDefinitionsFromStorageFileAsync(); StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); engagementManager.RegisterNotificationChannelAsync(); await BackgroundExecutionManager.RequestAccessAsync(); unregisterBackgroundTasks(); var backgroundTask = RegisterBackgroundTask("tasks.Class1", "Class1", new TimeTrigger(1440, false), new SystemCondition(SystemConditionType.UserNotPresent)); var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView(); setLaunchViewSize(appView); setMinAppSize(appView); if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView(); statusBar.BackgroundOpacity = 1; statusBar.ForegroundColor = ((SolidColorBrush)Application.Current.Resources["SystemControlForegroundAccentBrush"]).Color; statusBar.BackgroundColor = ((SolidColorBrush)Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]).Color; } var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues; if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Desktop") { var accentColorBrush = new SolidColorBrush((Color)Application.Current.Resources["SystemAccentColor"]).Color; ApplicationViewTitleBar formattableTitleBar = appView.TitleBar; formattableTitleBar.ButtonBackgroundColor = Colors.Transparent; formattableTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; formattableTitleBar.ButtonForegroundColor = accentColorBrush; CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.ExtendViewIntoTitleBar = true; appView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow); } Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; //rootFrame.Navigated += OnNavigated; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; // Register a handler for BackRequested events and set the // visibility of the Back button //SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; //SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = // rootFrame.CanGoBack ? // AppViewBackButtonVisibility.Visible : // AppViewBackButtonVisibility.Collapsed; } if (e.PrelaunchActivated == false) { var activationKind = e.Kind; if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter PackageVersion pv = Package.Current.Id.Version; object currentAppVersion = localSettings.Values["currentAppVersion"]; NavService = new Navigation(ref rootFrame); string applicationVersion = $"{pv.Major}.{pv.Minor}.{pv.Build}.{pv.Revision}"; prepareForTheCheckAndAskForReviewsAlgorithm(); if (currentAppVersion == null) { //Uncomment currentAppVersion change when you finish with testing onBoardingPage //localSettings.Values["currentAppVersion"] = applicationVersion; //When you finish the onBoardingPage, show it instead of the whatsNewPage App.NavService.NavigateTo(typeof(onBoardingPage), applicationVersion); } else if (currentAppVersion.ToString() != applicationVersion) { logger.Log($"Users updated to app version: {applicationVersion}"); localSettings.Values["currentAppVersion"] = applicationVersion; //Bring back the whatsNewPage for users who update at the end of your exams when you are officially back! //rootFrame.Navigate(typeof(whatsNewPage)); rootFrame.Navigate(typeof(whatsNewPage), e.Arguments); } else { if (!string.IsNullOrEmpty(e.Arguments)) { string tileID = e.Arguments; navigateBasedOnTileID(tileID, rootFrame); } else if (e.TileId != "") { if (e.TileId != "App") { navigateBasedOnTileID(e.TileId, rootFrame); } else { App.NavService.NavigateTo(typeof(MainPage), e.Arguments); } } else { App.NavService.NavigateTo(typeof(MainPage), e.Arguments); } } } else if (!string.IsNullOrEmpty(e.Arguments) && (string)e.Arguments == "Args") { string tileID = e.Arguments; navigateBasedOnTileID(tileID, rootFrame); } else { if (e.TileId != "") { if (e.TileId != "App") { navigateBasedOnTileID(e.TileId, rootFrame); } else { App.NavService.NavigateTo(typeof(MainPage), e.Arguments); } } } // Ensure the current window is active Window.Current.Activate(); } }
protected async override void OnActivated(IActivatedEventArgs e) { // Get the root frame Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; //rootFrame.Navigated += OnNavigated; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault(); engagementManager.RegisterNotificationChannelAsync(); await BackgroundExecutionManager.RequestAccessAsync(); unregisterBackgroundTasks(); var backgroundTask = RegisterBackgroundTask("tasks.Class1", "Class1", new TimeTrigger(1440, false), new SystemCondition(SystemConditionType.UserNotPresent)); var appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView(); setLaunchViewSize(appView); setMinAppSize(appView); if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView(); statusBar.BackgroundOpacity = 1; statusBar.ForegroundColor = ((SolidColorBrush)Application.Current.Resources["SystemControlForegroundAccentBrush"]).Color; statusBar.BackgroundColor = ((SolidColorBrush)Application.Current.Resources["SystemControlBackgroundChromeMediumLowBrush"]).Color; } var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues; if (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Desktop") { var accentColorBrush = new SolidColorBrush((Color)Application.Current.Resources["SystemAccentColor"]).Color; ApplicationViewTitleBar formattableTitleBar = appView.TitleBar; formattableTitleBar.ButtonBackgroundColor = Colors.Transparent; formattableTitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; formattableTitleBar.ButtonForegroundColor = accentColorBrush; CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar; coreTitleBar.ExtendViewIntoTitleBar = true; appView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow); } } if (rootFrame.Content == null) { NavService = new Navigation(ref rootFrame); } // Handle toast activation if (e is ToastNotificationActivatedEventArgs) { var toastActivationArgs = e as ToastNotificationActivatedEventArgs; // Parse the query string string args = toastActivationArgs.Argument; // See what action is being requested if (args == "comeBack" || args == "Yes") { logger.Log("Launched app from encouraging toast"); App.NavService.NavigateTo(typeof(MainPage), "comeBack"); } } // TODO: Handle other types of activation if (e.Kind == ActivationKind.VoiceCommand) { // Event args can represent many different activation types. // Cast it so we can get the parameters we care about out. var commandArgs = e as VoiceCommandActivatedEventArgs; Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = commandArgs.Result; // Get the name of the voice command and the text spoken. // See VoiceCommands.xml for supported voice commands. string voiceCommandName = speechRecognitionResult.RulePath[0]; string textSpoken = speechRecognitionResult.Text; // commandMode indicates whether the command was entered using speech or text. // Apps should respect text mode by providing silent (text) feedback. string commandMode = this.SemanticInterpretation("commandMode", speechRecognitionResult); switch (voiceCommandName) { case "createNewGoal": const string nullValue = "(null)"; string goalName = this.SemanticInterpretation("goalName", speechRecognitionResult); string target = this.SemanticInterpretation("target", speechRecognitionResult); string[] goalDetails = new string[] { goalName, target }; // Create a navigation command object to pass to the page. NavService.NavigateTo(typeof(addNewGoalPage), goalDetails); if (rootFrame.BackStackDepth > 0) { if (rootFrame.BackStack.Last().SourcePageType != typeof(MainPage)) { int backStackSize = rootFrame.BackStackDepth; rootFrame.BackStack.RemoveAt(backStackSize - 1); } } break; case "showGoalInProgress": goalName = this.SemanticInterpretation("goalInProgress", speechRecognitionResult); try { int itemCount = goal.listOfGoals.Where(item => item.name == goalName).Count(); if (itemCount > 0) { var goalInContext = goal.listOfGoals.Where(item => item.name == goalName).First(); NavService.NavigateTo(typeof(selectedGoalPage), goalInContext); } } catch (Exception) { NavService.NavigateTo(typeof(MainPage), "cortanaFailed"); } break; default: NavService.NavigateTo(typeof(MainPage), "cortanaFailed"); break; } } // Ensure the current window is active Window.Current.Activate(); }