public async void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { DeviceConnectionChangeTriggerDetails details = (DeviceConnectionChangeTriggerDetails)taskInstance.TriggerDetails; BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(details.DeviceId); SmartPack device = new SmartPack(bleDevice); if (bleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected) { if (device.AlertOnDevice && device.HasLinkLossService) { await device.SetAlertLevelCharacteristic(); } } else { if (device.AlertOnPhone) { XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Device {0} is out of range.", device.Name); ToastNotification toast = new ToastNotification(xml); ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier(); notifier.Show(toast); } } } finally { deferral.Complete(); } }
public void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance) { PrintNotificationEventDetails details = (PrintNotificationEventDetails)taskInstance.TriggerDetails; settings.Values[keyPrinterName] = details.PrinterName; settings.Values[keyAsyncUIXML] = details.EventData; // With the print notification event details we can choose to show a toast, update the tile, or update the badge. // It is not recommended to always show a toast, especially for non-actionable events, as it may become annoying for most users. // User may even just turn off all toasts from this app, which is not a desired outcome. // For events that does not require user's immediate attention, it is recommended to update the tile/badge and not show a toast. ShowToast(details.PrinterName, details.EventData); UpdateTile(details.PrinterName, details.EventData); UpdateBadge(); }
public void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance) { try { string value = Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("value") ? (string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["value"] : string.Empty; Windows.Data.Xml.Dom.XmlDocument xml = Windows.UI.Notifications.ToastNotificationManager .GetTemplateContent(Windows.UI.Notifications.ToastTemplateType.ToastText02); xml.GetElementsByTagName("text")[0].InnerText = "Time Zone Changed"; xml.GetElementsByTagName("text")[1].InnerText = value; Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().Show( new Windows.UI.Notifications.ToastNotification(xml)); } catch { } }
public void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance) { try { string value = Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("value") ? (string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["value"] : string.Empty; StringBuilder template = new StringBuilder(); template.Append("<toast><visual version='2'><binding template='ToastText02'>"); template.Append("<text id='2'>TimeZoneChanged</text>"); template.AppendFormat("<text id='1'>{0}</text>", value); template.Append("</binding></visual></toast>"); Windows.Data.Xml.Dom.XmlDocument xml = new Windows.Data.Xml.Dom.XmlDocument(); xml.LoadXml(template.ToString()); Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier().Show( new Windows.UI.Notifications.ToastNotification(xml)); } catch { } }