Exemplo n.º 1
0
        public static async Task CreateProgressToastAsync(string title, string status)
        {
            if (!ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
            {
                return;
            }

            // TODO: 8 Toast notificiation with binding
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(
                File.ReadAllText(Path.Combine(Package.Current.InstalledLocation.Path, @"Assets\Toasts\Upload.xml")));

            // Dictionary with all the elements to databind.
            var data = new Dictionary <string, string>
            {
                { "title", title },
                { "status", status },
                { "progressValue", "0" },
                { "progressValueStringOverride", "Calculating..." }
            };

            // Unique tag to reference the toast by
            s_tag = Guid.NewGuid().ToString();

            var toastNotification = new ToastNotification(xmlDocument)
            {
                Tag  = s_tag,
                Data = new NotificationData(data)
            };

            s_toastNotifier.Show(toastNotification);

            await BeginUploadImage(title);
        }
Exemplo n.º 2
0
        public static void ShowAddressAsToast(string address)
        {
            var toastText = toastXml.GetElementsByTagName("text");

            (toastText[0] as XmlElement).InnerText = "Your current Location:" + address;
            var toast = new ToastNotification(toastXml);

            toastNotifier.Show(toast);
        }
Exemplo n.º 3
0
        public void LongAlert(string message)
        {
            var         docStr = string.Format(templateStr, message);
            XmlDocument doc    = new XmlDocument();

            doc.LoadXml(docStr);
            var notification = new ToastNotification(doc);

            toastNotifier.Show(notification);
        }
        /*
         * Tooast notifications to show various success , progress or failures.
         */
        private void ShowToastNotification(string title, string stringContent)
        {
            // Initialize a ToastNotifier.
            ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();

            Windows.Data.Xml.Dom.XmlDocument toastXml      = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");

            // Add a title and a notification body.
            toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(title));
            toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent));
            Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            // Set audio property to play on notification.
            Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio");
            audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");

            ToastNotification toast = new ToastNotification(toastXml)
            {
                // Set the notification to disappeaar after 4 seconds.

                ExpirationTime = DateTime.Now.AddSeconds(4)
            };

            // Display the toast.
            ToastNotifier.Show(toast);
        }
Exemplo n.º 5
0
        public static async void actionsToast(string title, string content, string id)
        {
            string xml = "<toast>" +
                         "<visual>" +
                         "<binding template=\"ToastGeneric\">" +
                         "<text></text>" +
                         "<text></text>" +
                         "</binding>" +
                         "</visual>" +
                         "<actions>" +
                         "<input id=\"content\" type=\"text\" placeHolderContent=\"请输入评论\" />" +
                         "<action content = \"确定\" arguments = \"ok" + id + "\" activationType=\"background\" />" +
                         "<action content = \"取消\" arguments = \"cancel\" activationType=\"background\"/>" +
                         "</actions >" +
                         "</toast>";
            // 创建并加载XML文档
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            XmlNodeList elements = doc.GetElementsByTagName("text");

            elements[0].AppendChild(doc.CreateTextNode(title));
            elements[1].AppendChild(doc.CreateTextNode(content));
            // 创建通知实例
            ToastNotification notification = new ToastNotification(doc);
            //// 显示通知
            //DateTime statTime = DateTime.Now.AddSeconds(10);  //指定应传递 Toast 通知的时间
            //ScheduledToastNotification recurringToast = new ScheduledToastNotification(doc, statTime);  //创建计划的 Toast 通知对象
            //ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast); //向计划中添加 Toast 通知
            ToastNotifier nt = ToastNotificationManager.CreateToastNotifier();

            nt.Show(notification);
        }
Exemplo n.º 6
0
        private void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
        {
            var           toast         = args.ToastNotification;
            ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();

            ToastNotifier.Show(toast);
        }
Exemplo n.º 7
0
        public static void Show(ToastParameters parameters)
        {
            FileInfo tempIcon;

            if (parameters.IconUri != null && parameters.AppUserModelId != null)
            {
                tempIcon = new FileInfo(Path.Combine(Path.GetTempPath(), $"tmp_icon_{parameters.AppUserModelId}.png"));
                if (!tempIcon.Exists || DateTime.Now - tempIcon.LastWriteTime > TimeSpan.FromDays(7))
                {
                    using (var iconStream = Application.GetResourceStream(parameters.IconUri)?.Stream) {
                        if (iconStream != null)
                        {
                            using (var file = new FileStream(tempIcon.FullName, FileMode.Create)) {
                                iconStream.CopyTo(file);
                            }
                        }
                    }
                }
            }
            else
            {
                tempIcon = null;
            }

            var content = new XmlDocument();

            content.LoadXml(tempIcon == null ? $@"<toast>
    <visual>
        <binding template=""ToastText02"">
            <text id=""1"">{parameters.Title}</text>
            <text id=""2"">{parameters.Message}</text>
        </binding>
    </visual>
</toast>"
                    : $@"<toast>
    <visual>
        <binding template=""ToastImageAndText02"">
            <image id=""1"" src=""file://{tempIcon.FullName}""/>
            <text id=""1"">{parameters.Title}</text>
            <text id=""2"">{parameters.Message}</text>
        </binding>
    </visual>
</toast>");

            var toast = new ToastNotification(content);

            if (parameters.ClickCallback != null)
            {
                toast.Activated += (sender, args) => (Application.Current?.Dispatcher ?? Dispatcher.CurrentDispatcher).Invoke(parameters.ClickCallback);
            }

            if (_toastNotifier == null)
            {
                _toastNotifier = parameters.BoundToCallingApplication || parameters.AppUserModelId == null?
                                 ToastNotificationManager.CreateToastNotifier() :
                                     ToastNotificationManager.CreateToastNotifier(parameters.AppUserModelId);
            }

            _toastNotifier.Show(toast);
        }
Exemplo n.º 8
0
        public Task Show(PlaybackNotificationOptions options)
        {
            var toast             = BuildToast(options);
            var toastNotification = new ToastNotification(toast.GetXml());

            return(Task.Factory.StartNew(() => _toastNotifier.Show(toastNotification)));
        }
Exemplo n.º 9
0
 public void Notify()
 {
     foreach (var triggeredAlarm in _triggeredAlarms)
     {
         _toastNotifier.Show(MakeToast(triggeredAlarm.Report, triggeredAlarm.Alarm));
     }
 }
Exemplo n.º 10
0
        internal static void ShowToastMessage(string titleText, string messageText)
        {
            try
            {
                if (!string.IsNullOrEmpty(messageText) && messageText.Length > 50)
                {
                    messageText = messageText.Substring(0, 30); //Message toast length can't be norte then 47 characters
                }

                var      toastTextElements = toastXml.SelectNodes("/toast/visual/binding/text");
                IXmlNode node = toastTextElements[0].AppendChild(toastXml.CreateTextNode(titleText));
                toastTextElements[1].AppendChild(toastXml.CreateTextNode(messageText)); //

                var toastNode = toastXml.SelectSingleNode("/toast");
                //toastNode.Attributes.["duration"] = "long";
                // toastNode.SetAttribute("launch", '{"reason": "Toast", "error": "' + titleText + '"}');

                var toast = new ToastNotification(toastXml);


                toastNotifier.Show(toast);
#pragma warning disable CS0168 // The variable 'ex' is declared but never used
            }catch (Exception ex)
#pragma warning restore CS0168 // The variable 'ex' is declared but never used
            {
                //MessageHelper.showToastMessage("Message error", ex.Message);
            }
        }
Exemplo n.º 11
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            IReadOnlyList <GeofenceStateChangeReport> reports = GeofenceMonitor.Current.ReadReports();

            foreach (var report in reports)
            {
                if ((report.NewState != GeofenceState.None) &&
                    (report.NewState != GeofenceState.Removed))
                {
                    await StatusFile.AddStatusEntry(
                        report.Geofence.Id,
                        report.NewState == GeofenceState.Entered?EntryType.EnteredZone : EntryType.ExitedZone);
                }
            }

            XmlDocument template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);

            NotificationTemplateHelper.CompleteToastOrTileTemplate(
                template,
                new string[]
            {
                "One or more of our fences has been crossed"
            },
                null);

            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(new ToastNotification(template));

            deferral.Complete();
        }
Exemplo n.º 12
0
        public void showToast(ToastTemplateType type)
        {
            var xmlDoc       = ToastHelper.CreateToast(this, type);
            var notification = new ToastNotification(xmlDoc);

            _toastNotifier.Show(notification);
        }
Exemplo n.º 13
0
        public static void ToastMessage(string title, string message, string launchArgument = null)
        {
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            try
            {
                var xmlDoc = NotificationContentBuilder.CreateSimpleToastNotification(title, message, launchArgument);
                if (xmlDoc != null)
                {
                    ToastNotification notification  = new ToastNotification(xmlDoc);
                    ToastNotifier     toastNotifier = ToastNotificationManager.CreateToastNotifier();

                    toastNotifier.Show(notification);
                }
            }
            catch (Exception ex)
            {
                // we might have an exception if the message is too long
                TrackingManagerHelper.Exception(ex, string.Format("ToastMessage exception: {0}", ex.Message));
            }
        }
Exemplo n.º 14
0
        public void Show(string notificationTitle, string notificationText)
        {
            stringElements[0].FirstChild.InnerText = notificationTitle;
            stringElements[1].FirstChild.InnerText = notificationText;

            toastNotifier.Show(new Windows.UI.Notifications.ToastNotification(toastXml));
        }
        public void CreateToastWithXML_Click(object sender, RoutedEventArgs e)
        {
            XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04);

            /*
             * <toast>
             *	<visual>
             *		<binding template="ToastText04">
             *			<text id="1"></text>
             *			<text id="2"></text>
             *			<text id="3"></text>
             *		</binding>
             *	 </visual>
             *	</toast>
             */
            XmlNodeList nodes = toastXML.GetElementsByTagName("text");

            nodes[0].InnerText = "This is my header";
            nodes[1].InnerText = "Line 1";
            nodes[2].InnerText = "Line 2";
            //This does nothing in Toast Notifications
            //var binding = (XmlElement)toastXML.GetElementsByTagName("binding")[0];
            //binding.SetAttribute("branding", "none");

            //Add launch parameter
            toastXML.DocumentElement.SetAttribute("launch", "Activated from XML Toast");
            ToastNotification toast = new ToastNotification(toastXML);

            toast.Activated += toast_Activated;
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();

            notifier.Show(toast);
            TextBasedXML.Text = XDocument.Parse(toastXML.GetXml()).ToString();
        }
Exemplo n.º 16
0
        // 弹出 toast 通知(alarm 场景)
        // 经测试,没有按钮的话则无法实现 alarm 场景的特性
        private void buttonShowToast3_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的之前的全部 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' scenario='alarm' launch='Notification-Toast-Scenario-Arguments 3'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content 3</text>
                        </binding>
                    </visual>
                    <actions>
                        <action content='确认' arguments='confirm' />
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            ToastNotification toastNotification = new ToastNotification(toastDoc);
            ToastNotifier     toastNotifier     = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.Show(toastNotification);
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            try
            {
                DeviceConnectionChangeTriggerDetails details = (DeviceConnectionChangeTriggerDetails)taskInstance.TriggerDetails;
                BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(details.DeviceId);

                if (bleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected)
                {
                    XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                    xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Proximity tag {0} is connect.", bleDevice.Name);
                    ToastNotification toast    = new ToastNotification(xml);
                    ToastNotifier     notifier = ToastNotificationManager.CreateToastNotifier();
                    notifier.Show(toast);
                }
                else
                {
                    XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                    xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Proximity tag {0} is out of range.", bleDevice.Name);
                    ToastNotification toast    = new ToastNotification(xml);
                    ToastNotifier     notifier = ToastNotificationManager.CreateToastNotifier();
                    notifier.Show(toast);
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                deferral.Complete();
            }
        }
Exemplo n.º 18
0
        public static void CreateToast(String xml)
        {
            if (!ExecutionMode.IsRunningAsUwp())
            {
                return;
            }

            try
            {
                if (notifier == null)
                {
                    notifier = ToastNotificationManager.CreateToastNotifier();
                }
                else
                {
                    notifier.Hide(toast);
                }
                XmlDocument toastXml = new XmlDocument();
                toastXml.LoadXml(xml);

                toast = new ToastNotification(toastXml);
                notifier.Show(toast);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("CreateToast Error:" + ex.Message);
            }
        }
Exemplo n.º 19
0
        private static void ShowToast(string shortUserLevelMessage, Exception exception, string fullDetailedMessage, bool showSendReport = true)
        {
            var formForSynchronizing = Application.OpenForms.Cast <Form>().LastOrDefault();

            if (formForSynchronizing == null)
            {
                return;                 // can't safely show a toast, may be on wrong thread.
            }
            if (formForSynchronizing.InvokeRequired)
            {
                formForSynchronizing.BeginInvoke(new Action(() =>
                {
                    ShowToast(shortUserLevelMessage, exception, fullDetailedMessage, showSendReport);
                }));
                return;
            }
            var toast        = new ToastNotifier();
            var callToAction = string.Empty;

            if (showSendReport)
            {
                toast.ToastClicked +=
                    (s, e) =>
                {
                    ProblemReportApi.ShowProblemDialog(formForSynchronizing, exception, fullDetailedMessage, "nonfatal");
                };
                callToAction = "Report";
            }
            toast.Image.Image = ToastNotifier.WarningBitmap;
            toast.Show(shortUserLevelMessage, callToAction, 5);
        }
Exemplo n.º 20
0
        private async void SaveMatch(object sender, RoutedEventArgs e)
        {
            FolderPicker folderPicker = new FolderPicker();

            folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            folderPicker.FileTypeFilter.Add("*");
            StorageFolder folder = await folderPicker.PickSingleFolderAsync();

            ((Matchimpro)list_of_matches.SelectedItem).Save(folder);

            ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();

            Windows.Data.Xml.Dom.XmlDocument toastXml      = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
            var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();

            toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(resourceLoader.GetString("ExportTitle")));
            toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(resourceLoader.GetString("ExportMessage")));
            Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast");

            ToastNotification toast = new ToastNotification(toastXml);

            toast.ExpirationTime = DateTime.Now.AddSeconds(1);
            ToastNotifier.Show(toast);
        }
Exemplo n.º 21
0
        private void RaiseAToast(string title, string message)
        {
            ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
            XmlDocument   xd       = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            var elements = xd.GetElementsByTagName("text");

            if (!string.IsNullOrEmpty(title))
            {
                elements[0].AppendChild(xd.CreateTextNode(title));
            }

            if (!string.IsNullOrEmpty(message))
            {
                elements[1].AppendChild(xd.CreateTextNode(message));
            }

            ToastNotification tn = new ToastNotification(xd);

            try
            {
                notifier.Show(tn);
            }
            catch { }
        }
Exemplo n.º 22
0
        // 弹出 toast 通知(无 toast 通知 UI,仅放置于操作中心)
        private void buttonShowToast3_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的之前的全部 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = $@"
                <toast activationType='foreground' launch='Notification-Toast-Basic-Arguments 3'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>toast - content 3 {DateTime.Now.ToString("mm:ss")}</text>
                        </binding>
                    </visual>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            ToastNotification toast = new ToastNotification(toastDoc);

            toast.SuppressPopup = true; // 不会弹出 toast 通知 UI,但是会放置于操作中心
            toast.Tag           = "3";

            toast.Activated += Toast_Activated;
            toast.Dismissed += Toast_Dismissed;
            toast.Failed    += Toast_Failed;

            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.Show(toast);
        }
Exemplo n.º 23
0
        public void RefreshCallNotification(IEnumerable <Call> currentCalls)
        {
            IReadOnlyList <ToastNotification> notifications = ToastNotificationHistory.GetHistory();
            bool badState = notifications.Count == 0 || notifications.Any(x =>
            {
                if (x.Data != null)
                {
                    List <uint> ids         = x.Data.Values[USED_CALLS].Split(';').Where(y => !string.IsNullOrEmpty(y)).Select(y => uint.Parse(y)).ToList();
                    List <CallState> states = x.Data.Values[USED_CALLS_STATES].Split(';').Where(y => !string.IsNullOrEmpty(y)).Select(y => (CallState)Enum.Parse(typeof(CallState), y)).ToList();
                    List <Tuple <uint, CallState> > prev = ids.Join(states, y => ids.IndexOf(y), y => states.IndexOf(y), (x, y) => new Tuple <uint, CallState>(x, y)).ToList();
                    return(!prev.All(y => currentCalls.Any(z => z.ID == y.Item1 && z.State == y.Item2)));
                }
                else
                {
                    return(false);
                }
            });

            if (badState)
            {
                RemoveCallToastNotifications(notifications);
                ToastNotification notification = CreateCallNotification(currentCalls);
                if (notification != null)
                {
                    ToastNotifier.Show(notification);
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Helper method to display a toast notification.
        /// </summary>
        public static void DisplayToast(string message)
        {
            ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();

            // Create a two line toast and add audio reminder

            // Here the xml that will be passed to the
            // ToastNotification for the toast is retrieved
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            // Set both lines of text
            XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");

            toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Geolocation Sample"));
            toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(message));

            // now create a xml node for the audio source
            IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
            XmlElement audio     = toastXml.CreateElement("audio");

            audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");

            ToastNotification toast = new ToastNotification(toastXml);

            ToastNotifier.Show(toast);
        }
Exemplo n.º 25
0
        // 弹出 toast 通知(图文按钮)
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的之前的全部 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = @"
                <toast activationType='foreground' launch='Notification-Toast-ActionButton-Arguments 2'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>toast - title</text>
                            <text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text>
                        </binding>
                    </visual>
                    <actions>
                        <action content='确认' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 2 confirm' imageUri='Assets/StoreLogo.png' />
                        <action content='取消' activationType='foreground' arguments='Notification-Toast-ActionButton-Arguments 2 cancel' imageUri='Assets/StoreLogo.png' />
                    </actions>
                </toast>";

            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            ToastNotification toastNotification = new ToastNotification(toastDoc);
            ToastNotifier     toastNotifier     = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.Show(toastNotification);
        }
        private void ShowToastNotification(ToastNotification notification)
        {
            ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();

            notification.ExpirationTime = DateTime.Now.AddSeconds(4);
            ToastNotifier.Show(notification);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Helper method to pop a toast
        /// </summary>
        private void DoToast(int numEventsOfInterest, string eventName)
        {
            // pop a toast for each geofence event
            ToastNotifier ToastNotifier = ToastNotificationManager.CreateToastNotifier();

            // Create a two line toast and add audio reminder

            // Here the xml that will be passed to the
            // ToastNotification for the toast is retrieved
            Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            // Set both lines of text
            Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
            toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Geolocation Sample"));

            if (1 == numEventsOfInterest)
            {
                toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(eventName));
            }
            else
            {
                string secondLine = "There are " + numEventsOfInterest + " new geofence events";
                toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(secondLine));
            }

            // now create a xml node for the audio source
            Windows.Data.Xml.Dom.IXmlNode   toastNode = toastXml.SelectSingleNode("/toast");
            Windows.Data.Xml.Dom.XmlElement audio     = toastXml.CreateElement("audio");
            audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");

            ToastNotification toast = new ToastNotification(toastXml);

            ToastNotifier.Show(toast);
        }
Exemplo n.º 28
0
        private async Task SendNotificationAsync()
        {
            try
            {
                ReadRepository ReadRepository = new ReadRepository();
                var            events         = await ReadRepository.GetNextEvents();

                if (events == null && events.Count > 0)
                {
                    return;
                }

                ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
                XmlDocument   content  = ToastNotificationManager.GetTemplateContent(
                    ToastTemplateType.ToastImageAndText01);

                var texts = content.GetElementsByTagName("text");

                texts[0].InnerText = $"Usted tiene un evento próximo!!";

                texts[1].InnerText = $"El evento {events.First().Title} , se realizara el dia  {events.First().Date.ToLocalTime()}";

                var image = content.GetElementsByTagName("image");
                image[0].InnerText = events.First().Image;

                notifier.Show(new ToastNotification(content));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 29
0
        // 弹出 toast 通知(ms-appx 或 ms-appdata 地址的音频文件)
        private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
        {
            // 清除本 app 的之前的全部 toast 通知
            // ToastNotificationManager.History.Clear();

            string toastXml = $@"
                <toast activationType='foreground' launch='Notification-Toast-Audio-Arguments 1'>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>audio</text>
                            <text>演示 toast 的提示音</text>
                        </binding>
                    </visual>
                    <audio src='ms-appx:///Assets/audio.aac' />
                </toast>";

            XmlDocument toastDoc = new XmlDocument();

            toastDoc.LoadXml(toastXml);

            ToastNotification toastNotification = new ToastNotification(toastDoc);
            ToastNotifier     toastNotifier     = ToastNotificationManager.CreateToastNotifier();

            toastNotifier.Show(toastNotification);
        }
Exemplo n.º 30
0
        static void SendBatteryLowNotification()
        {
            if ((DateTime.Now - lastNotificationTime) < TimeSpan.FromMinutes(30))
            {
                return;
            }

            lastNotificationTime = DateTime.Now;

            var template  = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
            var textNodes = template.GetElementsByTagName("text");

            textNodes.Item(0).InnerText = $"Battery level low!";
            var notification = new ToastNotification(template);

            toastNotifier.Show(notification);
        }