示例#1
0
        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();
            }
        }
示例#2
0
        /// <summary>
        /// Shows a toast notification.
        /// </summary>
        /// <param name="notification">The object that supplies the new XML definition for the toast.</param>
        public void Show(ToastNotification notification)
        {
#if __ANDROID__
            ((Android.Widget.Toast)notification).Show();
#elif __MAC__
            NSUserNotificationCenter.DefaultUserNotificationCenter.DeliverNotification(notification);
#elif __UNIFIED__
            ShowImpl(notification);
#elif TIZEN
            Tizen.Applications.Notifications.Notification not = new Tizen.Applications.Notifications.EventNotification();
            not.Content = notification.Content;
            not.Title   = notification.Title;
            Tizen.Applications.Notifications.NotificationManager.Post(not);
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            _notifier.Show(notification);
#elif WINDOWS_PHONE
            notification._shellToast.Show();
#endif
        }