private async void RegisterToastBackgroundTasks() { string taskName = "ToastBackgroundTask"; // If background task is already registered, do nothing if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName))) { return; } // Otherwise request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // Create the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = taskName, }; // Assign the toast action trigger builder.SetTrigger(new ToastNotificationActionTrigger()); // And register the task BackgroundTaskRegistration registration = builder.Register(); }
private async Task <bool> RegisterBackgroundTask() { // Unregister any previous exising background task UnregisterBackgroundTask(); // Request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // If denied if (status != BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity && status != BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity) { return(false); } // Construct the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = BACKGROUND_ENTRY_POINT, TaskEntryPoint = BACKGROUND_ENTRY_POINT }; // Set trigger for Toast History Changed builder.SetTrigger(new ToastNotificationActionTrigger()); // And register the background task BackgroundTaskRegistration registration = builder.Register(); // And then listen for when the background task updates progress (it passes the toast change type) registration.Completed += BackgroundTask_Completed; return(true); }
/// <summary> /// Retrieve the status of the background synchronization task /// </summary> /// <returns>Sets the property BackgroundTask</returns> private async void BackgroundTaskStatus() { try { BackgroundAccessStatus _status = await BackgroundExecutionManager.RequestAccessAsync(); if (_status == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity) { var PebbleTimeTaskName = "Pebble Time Background Task"; //Check the current registration foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == PebbleTimeTaskName) { _backgroundtask = true; return; } } _backgroundtask = false; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("BackgroundTaskStatus: " + e.Message); } _backgroundtask = false; }
private async void Background_Click(object sender, RoutedEventArgs e) { BackgroundAccessStatus backgroundStatus = await BackgroundExecutionManager.RequestAccessAsync(); switch (backgroundStatus) { case BackgroundAccessStatus.AllowedSubjectToSystemPolicy: Debug.WriteLine("Фоновые задачи доступны частично"); BackgroundRegister(); break; case BackgroundAccessStatus.AlwaysAllowed: Debug.WriteLine("Фоновые задачи полностью поддерживаются"); BackgroundRegister(); break; case BackgroundAccessStatus.DeniedBySystemPolicy: Debug.WriteLine("Фоновые задачи отключены или недоступны"); break; case BackgroundAccessStatus.DeniedByUser: Debug.WriteLine("Фоновые задачи отключены пользователем"); break; } }
/// <summary> /// This is the click handler for the 'Enable' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ScenarioEnable(object sender, RoutedEventArgs e) { Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged); if (null != Accelerometer) { // Make sure this app is allowed to run background tasks. // RequestAccessAsync must be called on the UI thread. BackgroundAccessStatus accessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if ((BackgroundAccessStatus.AlwaysAllowed == accessStatus) || (BackgroundAccessStatus.AllowedSubjectToSystemPolicy == accessStatus)) { if (await StartSensorBackgroundTaskAsync(Accelerometer.DeviceId)) { _refreshTimer.Start(); ScenarioEnableButton.IsEnabled = false; ScenarioDisableButton.IsEnabled = true; } } else { rootPage.NotifyUser("Background tasks may be disabled for this app", NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("No accelerometer found", NotifyType.StatusMessage); } }
/// <summary> /// This is the click handler for the 'Register' button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async private void RegisterBackgroundTask(object sender, RoutedEventArgs e) { try { // Get permission for a background task from the user. If the user has already answered once, // this does nothing and the user must manually update their preference via PC Settings. BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); // Regardless of the answer, register the background task. If the user later adds this application // to the lock screen, the background task will be ready to run. // Create a new background task builder BackgroundTaskBuilder geofenceTaskBuilder = new BackgroundTaskBuilder(); geofenceTaskBuilder.Name = SampleBackgroundTaskName; geofenceTaskBuilder.TaskEntryPoint = SampleBackgroundTaskEntryPoint; // Create a new location trigger var trigger = new LocationTrigger(LocationTriggerType.Geofence); // Associate the locationi trigger with the background task builder geofenceTaskBuilder.SetTrigger(trigger); // If it is important that there is user presence and/or // internet connection when OnCompleted is called // the following could be called before calling Register() // SystemCondition condition = new SystemCondition(SystemConditionType.UserPresent | SystemConditionType.InternetAvailable); // geofenceTaskBuilder.AddCondition(condition); // Register the background task _geofenceTask = geofenceTaskBuilder.Register(); // Associate an event handler with the new background task _geofenceTask.Completed += OnCompleted; UpdateButtonStates(/*registered:*/ true); switch (backgroundAccessStatus) { case BackgroundAccessStatus.AlwaysAllowed: case BackgroundAccessStatus.AllowedSubjectToSystemPolicy: // BackgroundTask is allowed _rootPage.NotifyUser("Geofence background task registered.", NotifyType.StatusMessage); // Need to request access to location // This must be done with the background task registeration // because the background task cannot display UI. RequestLocationAccess(); break; default: _rootPage.NotifyUser("Background tasks may be disabled for this app", NotifyType.ErrorMessage); break; } } catch (Exception ex) { _rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage); UpdateButtonStates(/*registered:*/ false); } }
private async Task <bool> RegisterBackgroundTask() { // Unregister any previous exising background task UnregisterBackgroundTask(); _status += "Constructing task\n"; // Request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // If denied if (status != BackgroundAccessStatus.AlwaysAllowed && status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy) { return(false); } // Construct the background task var builder = new BackgroundTaskBuilder(); builder.Name = BACKGROUND_ENTRY_POINT; builder.TaskEntryPoint = BACKGROUND_ENTRY_POINT; builder.IsNetworkRequested = true; // Set trigger PushNotificationTrigger trigger = new PushNotificationTrigger(); builder.SetTrigger(trigger); // Register Background task BackgroundTaskRegistration registration = builder.Register(); _status += "Task registered\n"; return(true); }
async void ClientInit() { commModule = new CommModule(); if (lockScreenAdded == false) { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); Diag.DebugPrint("Lock screen status " + status); switch (status) { case BackgroundAccessStatus.AlwaysAllowed: case BackgroundAccessStatus.AllowedSubjectToSystemPolicy: lockScreenAdded = true; break; case BackgroundAccessStatus.DeniedBySystemPolicy: case BackgroundAccessStatus.DeniedByUser: Diag.DebugPrint("As lockscreen status was Denied, app should switch to polling mode such as email based on time triggers"); break; } } btnConnection.Visibility = Visibility.Visible; return; }
public static async Task <bool> RegisterTimeZoneChangeBackgroundTask(string name, string entryPoint) { bool result = false; try { UnregisterBackgroundTasks(); BackgroundAccessStatus accessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if (accessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity || accessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity) { BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = name; builder.TaskEntryPoint = entryPoint; builder.SetTrigger(new SystemTrigger(SystemTriggerType.TimeZoneChange, false)); builder.Register(); result = true; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } return(result); }
private async void RegisterBackgroundTask() { Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged); if (null != alti) { // Make sure this app is allowed to run background tasks. // RequestAccessAsync must be called on the UI thread. BackgroundExecutionManager.RemoveAccess(); BackgroundAccessStatus accessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if (accessStatus == BackgroundAccessStatus.Denied) { await new MessageDialog("后台任务被禁止!").ShowAsync(); return; } if (await StartSensorBackgroundTaskAsync(alti.DeviceId)) { Open_Button.IsEnabled = false; Close_Button.IsEnabled = true; } } else { Debug.WriteLine("BackgroundNo accelerometer found"); } }
private async void RegisterBackgroundTask() { UnregisterBackgroundTask(); try { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); Debug.WriteLine("BackgroundAccessStatus: " + status); } catch (Exception ex) { Debug.WriteLine(ex.Message); } // A background task can be registered even if lock screen access was denied. BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = taskName; builder.TaskEntryPoint = "QuestionsBackgroundTasks.TimerTask"; builder.SetTrigger(new TimeTrigger(15, false)); BackgroundTaskRegistration task = builder.Register(); taskCompletedHandler = new BackgroundTaskCompletedEventHandler(OnTaskCompleted); task.Completed += OnTaskCompleted; }
public static async void RegisterSingleProcessTask() { string taskName = "SingleTask"; foreach (var registeredTask in BackgroundTaskRegistration.AllTasks) { if (registeredTask.Value.Name == taskName) { return; } } BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); if (status == BackgroundAccessStatus.Denied) { return; } var builder = new BackgroundTaskBuilder(); builder.Name = "SingleTaskTrigger"; builder.SetTrigger(new TimeTrigger(15, true)); // use builder.TaskEntryPoint if you want to not use the default OnBackgroundActivated // we’ll register it and now will start work based on the trigger, here we used a Time Trigger BackgroundTaskRegistration task = builder.Register(); }
public static async void RegisterBackgroundTask(string taskName, string entryPoint) { foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == taskName) { return; } } BackgroundExecutionManager.RemoveAccess(); BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); if (status == BackgroundAccessStatus.Denied) { return; } SystemCondition internetCondition = new SystemCondition(SystemConditionType.InternetAvailable); var builder = new BackgroundTaskBuilder(); builder.Name = taskName; builder.TaskEntryPoint = entryPoint; var timeTrigger = new TimeTrigger(16, false); builder.SetTrigger(timeTrigger); //builder.SetTrigger(new SystemTrigger(SystemTriggerType.PowerStateChange, false)); builder.AddCondition(internetCondition); BackgroundTaskRegistration taskRegistered = builder.Register(); }
private async Task RegisterBackgroundTask() { foreach (var task in BackgroundTaskRegistration.AllTasks) { task.Value.Unregister(true); } BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); builder.Name = "PodCatchHouseKeeping"; builder.TaskEntryPoint = "PodCatch.BackgroundTasks.BackgroundTask"; builder.SetTrigger(new MaintenanceTrigger(15, false)); builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); builder.AddCondition(new SystemCondition(SystemConditionType.UserNotPresent)); try { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); IBackgroundTaskRegistration backgroundTaskRegistration = builder.Register(); backgroundTaskRegistration.Completed += ((s, a) => UIThread.RunInBackground(() => Data.Load(true))); } catch (Exception ex) { Tracer.TraceError("Error registering background task: {0}", ex); } }
private async Task <bool> RegisterBackgroundTask() { // Unregister any previous exising background task UnregisterBackgroundTask(); // Request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // If denied if (status != BackgroundAccessStatus.AlwaysAllowed && status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy) { return(false); } // Construct the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = BACKGROUND_ENTRY_POINT, TaskEntryPoint = BACKGROUND_ENTRY_POINT }; // Set trigger for Toast History Changed builder.SetTrigger(new ToastNotificationActionTrigger()); // And register the background task BackgroundTaskRegistration registration = builder.Register(); return(true); }
/// <summary> /// Creates secondary tile if it is not yet created or removes the tile if it already exists. /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">Event arguments</param> private async void ApplicationBar_PinTile(object sender, RoutedEventArgs e) { bool removeTile = SecondaryTile.Exists(TILE_ID); if (removeTile) { await RemoveBackgroundTaskAsync("StepTriggered"); } else { ApiSupportedCapabilities caps = await SenseHelper.GetSupportedCapabilitiesAsync(); // Use StepCounterUpdate to trigger live tile update if it is supported. Otherwise we use time trigger if (caps.StepCounterTrigger) { var myTrigger = new DeviceManufacturerNotificationTrigger(SenseTrigger.StepCounterUpdate, false); await RegisterBackgroundTaskAsync(myTrigger, "StepTriggered", "BackgroundTasks.StepTriggerTask"); } else { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); IBackgroundTrigger trigger = new TimeTrigger(15, false); await RegisterBackgroundTaskAsync(trigger, "StepTriggered", "BackgroundTasks.StepTriggerTask"); } } await CreateOrRemoveTileAsync(removeTile); }
private async Task <bool> RegisterRawNotificationBackgroundTask() { // Unregister any previous exising background task UnregisterBackgroundTask(RAW_BACKGROUND_ENTRY_POINT); // Request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // If denied if (status != BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity && status != BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity) { return(false); } // Construct the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = RAW_BACKGROUND_ENTRY_POINT, TaskEntryPoint = RAW_BACKGROUND_ENTRY_POINT }; // Set trigger for Toast History Changed builder.SetTrigger(new PushNotificationTrigger()); // And register the background task BackgroundTaskRegistration registration = builder.Register(); return(true); }
private async Task RegisterBackgroundTask() { BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); var geofenceTaskBuilder = new BackgroundTaskBuilder { Name = "My Home Geofence", TaskEntryPoint = "GeofenceTask.BackgroundGeofenceTask" }; var trigger = new LocationTrigger(LocationTriggerType.Geofence); geofenceTaskBuilder.SetTrigger(trigger); var geofenceTask = geofenceTaskBuilder.Register(); geofenceTask.Completed += GeofenceTask_Completed; switch (backgroundAccessStatus) { case BackgroundAccessStatus.Unspecified: case BackgroundAccessStatus.Denied: ShowMessage("This application is denied of the background task "); break; } }
}//Constructor End /// <summary> /// Function to Request Background Access, Sets BackgroundRequestGranted to 'true' if granted /// Also checks if the accelerometer exists /// </summary> async void RequestBackgroundAccessAsync() { if (_acclerometer != null) { manualTrigger = new DeviceUseTrigger(); BackgroundAccessStatus accessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if ((BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity == accessStatus) || (BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity == accessStatus)) { BackgroundRequestGranted = true; return; } else { #warning shift to UI Error = "Background tasks may be disabled for this app"; return; } } else { #warning shift to UI Error = "Accelerometer unavailable"; return; } }//RequestBackgroundAccess end
private async void RegisterBackgroundTask() { BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync(); if (backgroundAccessStatus == BackgroundAccessStatus.AlwaysAllowed || backgroundAccessStatus == BackgroundAccessStatus.AllowedSubjectToSystemPolicy) { foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == taskName) { task.Value.Unregister(true); } } BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder(); taskBuilder.Name = taskName; taskBuilder.TaskEntryPoint = taskEntryPoint; taskBuilder.SetTrigger(new TimeTrigger(5, false)); var registration = taskBuilder.Register(); App.Debug("Background task registration initiated for " + taskName + "."); } else { var messageDialog = new MessageDialog("Background registration not attempted."); await messageDialog.ShowAsync(); } }
private async Task <bool> BackgroundAccessQuery() { bool ret = true; try { BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); if (status == BackgroundAccessStatus.DeniedBySystemPolicy) { await(new MessageDialog(bckSys)).ShowAsync(); ret = false; } else if (status == BackgroundAccessStatus.DeniedByUser) { MessageDialog dialog = new MessageDialog(bckUsr); dialog.Commands.Add(new UICommand(sett, async args => { await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-backgroundapps")); MessageDialog dlg = new MessageDialog(dlgRefresh); dlg.Commands.Add(new UICommand(dlgRefreshBt, async ags => ret = await BackgroundAccessQuery())); await dlg.ShowAsync(); })); dialog.Commands.Add(new UICommand(dlgCancel, args => ret = false)); await dialog.ShowAsync(); } } catch { ret = false; } return(ret); }
//static void Unegister() //{ // foreach (var task in BackgroundTaskRegistration.AllTasks) // { // Debug.WriteLine(task.Value.Name); // switch (task.Value.Name) // { // case ENTRY_POINT: // task.Value.Unregister(true); // return; // } // } //} //public static async void RegisterX() //{ // //try // //{ // // Unegister(); // // await Task.Delay(250); // // var builder = new BackgroundTaskBuilder // // { // // Name = ENTRY_POINT, // // TaskEntryPoint = ENTRY_POINT // // }; // // builder.SetTrigger(new ToastNotificationActionTrigger()); // // builder.Register(); // //} // //catch { } //} public async static void Register() { try { if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(ENTRY_POINT))) { ($"{ENTRY_POINT} background task already registered.").PrintDebug(); return; } BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); BackgroundTaskBuilder builder = new BackgroundTaskBuilder { Name = ENTRY_POINT, TaskEntryPoint = ENTRY_POINT }; builder.SetTrigger(new ToastNotificationActionTrigger()); builder.Register(); ($"{ENTRY_POINT} background task registered.").PrintDebug(); } catch { } }
private async static Task RegisterToastBackgroundTaskAsync() { // If background task is already registered, do nothing if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(TOAST_BACKGROUND_TASK_NAME))) { Logger.Info(TOAST_BACKGROUND_TASK_NAME + " background task already registered."); return; } // Otherwise request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // Create the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder { Name = TOAST_BACKGROUND_TASK_NAME }; // Assign the toast action trigger builder.SetTrigger(new ToastNotificationActionTrigger()); // And register the task builder.Register(); Logger.Info("Registered " + TOAST_BACKGROUND_TASK_NAME + " background task."); }
public static void RegisterBackgroundTask(string taskEntryPoint, string taskName, IBackgroundTrigger trigger, IBackgroundCondition condition) { foreach (var cur in BackgroundTaskRegistration.AllTasks) { if (cur.Value.Name == taskName) { return; } } BackgroundAccessStatus status = BackgroundExecutionManager.RequestAccessAsync().AsTask().Result; if (status == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity || status == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity) { var builder = new BackgroundTaskBuilder(); builder.Name = taskName; builder.TaskEntryPoint = taskEntryPoint; builder.SetTrigger(trigger); if (condition != null) { builder.AddCondition(condition); } builder.Register(); } else { throw new Exception(); } }
private static async void RegisterBackgroundTask(string taskName, string entryPoint, uint interval = 60) { foreach (var task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == taskName) { return; } } BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); if (status == BackgroundAccessStatus.DeniedBySystemPolicy || status == BackgroundAccessStatus.DeniedByUser) { return; // show message that task couldn't be registered } var builder = new BackgroundTaskBuilder() { Name = taskName, TaskEntryPoint = entryPoint }; builder.SetTrigger(new TimeTrigger(interval, false)); BackgroundTaskRegistration taskRegistered = builder.Register(); }
/// <summary> /// 注册后台更新主磁贴任务。 /// </summary> public static async void RegisterBackgroundTileUpdateTask() { foreach (KeyValuePair <Guid, IBackgroundTaskRegistration> task in BackgroundTaskRegistration.AllTasks) { if (task.Value.Name == "TileTask") { // 已经注册后台任务。 return; } } BackgroundAccessStatus access = await BackgroundExecutionManager.RequestAccessAsync(); if (access != BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity) { // 没有权限。 return; } BackgroundTaskBuilder builder = new BackgroundTaskBuilder(); // 仅在网络可用下执行后台任务。 builder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable)); builder.Name = "TileTask"; builder.TaskEntryPoint = "SoftwareKobo.BingWallpaper.BackgroundTask.UpdateTileTask"; // 每 90 分钟触发一次。 builder.SetTrigger(new TimeTrigger(90, false)); BackgroundTaskRegistration registration = builder.Register(); }
private async Task <bool> RegisterBackgroundTask() { // Unregister any previous exising background task UnregisterBackgroundTask(); // Request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // If denied if (status != BackgroundAccessStatus.AlwaysAllowed && status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy) { return(false); } // Construct the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = BACKGROUND_TASK_NAME, TaskEntryPoint = "BackgroundTasks.ToastNotificationHistoryChangedTriggerTask" }; // Set trigger for Toast History Changed builder.SetTrigger(new ToastNotificationHistoryChangedTrigger()); // And register the background task BackgroundTaskRegistration registration = builder.Register(); // And then listen for when the background task updates progress (it passes the toast change type) registration.Progress += BackgroundTask_Progress; return(true); }
private static bool IsBackgroundAccessValid(BackgroundAccessStatus bgStatus) { var status = default(bool); switch (bgStatus) { //case BackgroundAccessStatus.DeniedBySystemPolicy: case BackgroundAccessStatus.Denied: case BackgroundAccessStatus.Unspecified: break; //case BackgroundAccessStatus.AlwaysAllowed: //case BackgroundAccessStatus.AllowedSubjectToSystemPolicy: case BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity: case BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity: status = true; break; default: //AllowedMayUseActiveRealTimeConnectivity status = true; break; } return(status); }
public static async Task RegisterBackgroundTaskAsync() { try { // If background task is already registered, do nothing if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(TOAST_BACKGROUND_TASK))) { IsToastBackgroundTaskRegistered = true; return; } // Otherwise request access BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // Create the background task BackgroundTaskBuilder builder = new BackgroundTaskBuilder() { Name = TOAST_BACKGROUND_TASK }; // Assign the toast action trigger builder.SetTrigger(new ToastNotificationActionTrigger()); // And register the task BackgroundTaskRegistration registration = builder.Register(); // Flag that the task is registered IsToastBackgroundTaskRegistered = true; } catch { // Report to telemetry } }
private async static Task RegisterPushBackgroundTaskAsync() { // If background task is already registered, do nothing: if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(PUSH_BACKGROUND_TASK_NAME))) { Logger.Info(PUSH_BACKGROUND_TASK_NAME + " background task already registered."); return; } // Otherwise request access: BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync(); // Create the background task: BackgroundTaskBuilder builder = new BackgroundTaskBuilder { Name = PUSH_BACKGROUND_TASK_NAME }; // Assign the push notification trigger: builder.SetTrigger(new PushNotificationTrigger()); builder.TaskEntryPoint = "Push_BackgroundTask.Classes.PushBackgroundTask"; // And register the task: builder.Register().Completed += OnBackgroundTaskRegistrationCompleted; Logger.Info("Registered " + PUSH_BACKGROUND_TASK_NAME + " background task."); }