private static void notificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { string receiver = args.RawNotification.Content; if (CommonData.session!=null && receiver == CommonData.session.Username) { if (CommonData.activeConversationPage != null) { CommonData.activeConversationPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { CommonData.activeConversationPage.refreshMessages(null, null); }); } } else { foreach (string[] credential in DataStorage.GetNotifierCredentials()) { if (receiver == credential[0]) { ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); var toastTextElements = toastXml.GetElementsByTagName("text"); ResourceLoader resourceGetter = new ResourceLoader(); string appName = resourceGetter.GetString("ApplicationTitle"); string notificationText = resourceGetter.GetString("NotifierNewMessageText") + credential[0]; toastTextElements[0].AppendChild(toastXml.CreateTextNode(appName)); toastTextElements[1].AppendChild(toastXml.CreateTextNode(notificationText)); ToastNotification toast = new ToastNotification(toastXml); ToastNotificationManager.CreateToastNotifier().Show(toast); } } } }
private void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { Debug.WriteLine("Push Notification Received " + args.NotificationType); JObject jobject = null; switch (args.NotificationType) { case PushNotificationType.Badge: jobject = JObject.FromObject(args.BadgeNotification, serializer); break; case PushNotificationType.Raw: jobject = JObject.FromObject(args.RawNotification, serializer); break; case PushNotificationType.Tile: jobject = JObject.FromObject(args.TileNotification, serializer); break; #if WINDOWS_UWP || WINDOWS_PHONE_APP case PushNotificationType.TileFlyout: jobject = JObject.FromObject(args.TileNotification, serializer); break; #endif case PushNotificationType.Toast: jobject = JObject.FromObject(args.ToastNotification, serializer); break; } Debug.WriteLine("Sending JObject to PushNotificationListener " + args.NotificationType); CrossPushNotification.PushNotificationListener.OnMessage(jobject, DeviceType.Windows); }
void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { string typeString = String.Empty; string notificationContent = String.Empty; switch (e.NotificationType) { case PushNotificationType.Badge: typeString = "Badge"; notificationContent = e.BadgeNotification.Content.GetXml(); break; case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); typeString = "Tile"; break; case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); typeString = "Toast"; // Setting the cancel property prevents the notification from being delivered. It's especially important to do this for toasts: // if your application is already on the screen, there's no need to display a toast from push notifications. e.Cancel = true; break; case PushNotificationType.Raw: notificationContent = e.RawNotification.Content; typeString = "Raw"; break; } string text = "Received a " + typeString + " notification, containing: " + notificationContent; var ignored = dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser(text, NotifyType.StatusMessage); }); }
private async void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { String notificationContent = String.Empty; switch (e.NotificationType) { case PushNotificationType.Badge: notificationContent = e.BadgeNotification.Content.GetXml(); break; case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); break; case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); break; case PushNotificationType.Raw: notificationContent = e.RawNotification.Content; break; } System.Diagnostics.Debug.WriteLine("received notification:\n" + notificationContent); //e.Cancel = true; }
/// <summary> /// Helper method to extract the full Push JSON provided to Parse, including any /// non-visual custom information. Overloads exist for all data types which may be /// provided by Windows, I.E. LaunchActivatedEventArgs and PushNotificationReceivedEventArgs. /// Returns an empty dictionary if this push type cannot include non-visual data or /// this event was not triggered by a push. /// </summary> public static IDictionary<string, object> PushJson(PushNotificationReceivedEventArgs eventArgs) { var toast = eventArgs.ToastNotification; if (toast == null) { return new Dictionary<string, object>(); } return PushJson(toast); }
void _channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { if (PushNotificationReceived != null) { PushNotificationReceived(sender, args); } }
public void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { if (e.NotificationType == PushNotificationType.Toast) { this.RefreshOrders(); } }
/// <summary> /// Handles push notifications from mobile services. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private static async void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { switch(args.NotificationType) { case PushNotificationType.Toast: // If there is a currently active game, get it and call ProcessRemoteTurn. if (MainPage.GetMainPage().Processor != null) { await MainPage.GetMainPage().Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => MainPage.GetMainPage().Processor.HandleToastNotification()); } break; case PushNotificationType.Badge: if (MainPage.GetMainPage() != null) { await MainPage.GetMainPage().Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => MainPage.GetMainPage().HandleBadgeNotification(args.BadgeNotification)); args.Cancel = true; } break; case PushNotificationType.Raw: break; } }
private static void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { TypedEventHandler<PushNotificationChannel, PushNotificationReceivedEventArgs> handler = PushNotificationReceived; if (handler != null) { handler(sender, args); } }
private async void notificationChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _timer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 5) }; _timer.Tick += timer_Tick; _timer.Start(); }); }
static void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { if (args.NotificationType == PushNotificationType.Raw) { DispatcherHelper.CheckBeginInvokeOnUI(() => { var vote = JObject.Parse(args.RawNotification.Content).ToObject<RawVote>(); Messenger.Default.Send<RawVote>(vote); }); } }
private void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { if (args.ToastNotification == null) return; var message = args.ToastNotification.Content.InnerText; var launch = args.ToastNotification.Content.GetElementsByTagName("toast")[0].Attributes.GetNamedItem("launch"); IDictionary<string, string> data = new Dictionary<string, string>(); if (launch != null) { data = UrlQueryParser.ParseQueryString(launch.InnerText); } OnPushNotification(message, data); }
void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { try { if (args.NotificationType == PushNotificationType.Raw) { var message = JsonConvert.DeserializeObject<MessageMemento>( args.RawNotification.Content); if (MessageReceived != null) MessageReceived(Message.FromMemento(message)); } } catch (Exception x) { // Ignore bad notification messages } }
private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { string notificationContent = String.Empty; switch (e.NotificationType) { case PushNotificationType.Badge: notificationContent = e.BadgeNotification.Content.GetXml(); break; case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); break; case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); break; } // prevent the notification from being delivered to the UI e.Cancel = true; }
private void CurrentChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { //lock (this) //{ // var messageContent = args.ToastNotification.Content; // var textElements = messageContent.GetElementsByTagName("text"); // var imgElement = messageContent.GetElementsByTagName("image"); // var msgId = textElements.ElementAt(4).InnerText; // var id = textElements.ElementAt(3).InnerText; // var userId = textElements.ElementAt(5).InnerText; // var ownerId = textElements.ElementAt(6).InnerText; // var msgContent = textElements.ElementAt(1).InnerText; // var msgDate = textElements.ElementAt(2).InnerText; // var userName = textElements.ElementAt(0).InnerText; // var avatar = imgElement.ElementAt(0).Attributes[1].InnerText; // var chatMessage = new MessageInbox() // { // MessageId = int.Parse(msgId), // UserId = int.Parse(userId), // OwnerId = int.Parse(ownerId), // UserName = userName, // Avatar = avatar // }; // var chatMessageDetail = new InboxDetail() // { // ID = int.Parse(id), // MessageId = int.Parse(msgId), // UserId = int.Parse(userId), // UserName = userName, // Avatar = avatar, // Content = msgContent, // InboxDate = Convert.ToDateTime(string.Format(msgDate, "MM/dd/yyyy HH:mm:ss")) // }; // if (MediateClass.MessageVM.MessageList.Count(x => x.MessageId == chatMessage.MessageId) == 0) // MediateClass.MessageVM.MessageList.Add(chatMessage); // MediateClass.MsgDetailVM.DetailList.Insert(0, chatMessageDetail); //} }
void service_OnPushAccepted(object sender, Windows.Networking.PushNotifications.PushNotificationReceivedEventArgs e) { String notificationContent = String.Empty; String type = String.Empty; switch (e.NotificationType) { case PushNotificationType.Badge: notificationContent = e.BadgeNotification.Content.GetXml(); type = "Badge"; break; case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); type = "Tile"; break; case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); type = "Toast"; break; case PushNotificationType.Raw: notificationContent = e.RawNotification.Content; type = "Raw"; break; } Debug.WriteLine("Received {0} notification", type); Debug.WriteLine("Notification content: " + notificationContent); var alert = new MessageDialog("Notification content: " + notificationContent, type + " received"); alert.ShowAsync(); }
static void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { string result = args.NotificationType.ToString(); switch (args.NotificationType) { case PushNotificationType.Badge: result += ": " + args.BadgeNotification.Content.GetXml(); break; case PushNotificationType.Raw: result += ": " + args.RawNotification.Content; break; case PushNotificationType.Tile: result += ": " + args.TileNotification.Content.GetXml(); break; case PushNotificationType.TileFlyout: result += ": " + args.TileNotification.Content.GetXml(); break; case PushNotificationType.Toast: result += ": " + args.ToastNotification.Content.GetXml(); break; default: break; } }
private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { NotificationData notificationData = null; try { //Decide what to do when a notification arrives while the app is running switch (args.NotificationType) { case PushNotificationType.Toast: var toastNotification = JsonConvert.DeserializeObject<IToastText02>(args.ToastNotification.Content.GetXml()); notificationData = new NotificationData { AlertMessage = String.Concat(toastNotification.TextHeading.Text, " ", toastNotification.TextBodyWrap.Text), CustomDataJsonString = toastNotification.Launch, AppWasRunning = true }; break; case PushNotificationType.Tile: break; case PushNotificationType.Badge: break; case PushNotificationType.Raw: break; } } catch (Exception e) { WindowsPhoneUtils.Log(String.Concat("Error on PushNotification received: ", e.Message)); } WindowsPhoneUtils.InvokeCallback("Appverse.PushNotifications.OnRemoteNotificationReceived", WindowsPhoneUtils.CALLBACKID, JsonConvert.SerializeObject(notificationData)); //Show Push notification even when app is in foreground args.Cancel = false; }
/// <summary> /// Handles a push notification being received whilst the app is live. If we receive a toast, /// it is likely we have received an invite. If we receive a tile, it's probably that we /// have a new item. /// </summary> void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { _synchronizationContext.Post(ignored => { if (args.NotificationType == PushNotificationType.Toast) { // we received a toast notification - let's check for invites LoadInvites(); } else if (args.NotificationType == PushNotificationType.Tile) { // we received a tile - reload current items in case it was for this list LoadItems(); } }, null); }
void channel_PushNotificationReceived(Windows.Networking.PushNotifications.PushNotificationChannel sender, Windows.Networking.PushNotifications.PushNotificationReceivedEventArgs args) { if (args.ToastNotification.Content.InnerText.Contains("Event")) { //args.Cancel = true; } else { args.Cancel = true; //items = await Table.OrderByDescending(ChatPublic => ChatPublic.CreatedAt).Take(1).ToCollectionAsync(); //await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => //{ // ChatPubList a = new ChatPubList(); // a.Message = items[0].Message; // a.Name = items[0].Name; // MainPage.test.Insert(0, a); //}); } }
async void channel_PushNotificationReceived(Windows.Networking.PushNotifications.PushNotificationChannel sender, Windows.Networking.PushNotifications.PushNotificationReceivedEventArgs args) { if (args.ToastNotification.Content.InnerText.Contains("Event")) { } else { args.Cancel = true; items = await Table.OrderByDescending(ChatPublic => ChatPublic.CreatedAt).Take(1).ToCollectionAsync(); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ChatPubList a = new ChatPubList(); a.date = items[0].CreatedAt.Date.ToString(); a.time = items[0].CreatedAt.TimeOfDay.ToString(); a.time = a.time.Remove(5); a.date = a.date.Remove(10); a.Message = items[0].Message; a.Name = items[0].Name; var networkProfiles = Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles(); var adapter = networkProfiles.First <Windows.Networking.Connectivity.ConnectionProfile>().NetworkAdapter;//takes the first network adapter string networkAdapterId = adapter.NetworkAdapterId.ToString(); if (a.Name == networkAdapterId) { a.col = "#FF9B0E00"; } else { a.col = "#FF5D340C"; } MainPage.test.Insert(0, a); }); } }
private async void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { if (e.NotificationType == PushNotificationType.Raw) { e.Cancel = true; await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Raw notification received with content: " + e.RawNotification.Content, NotifyType.StatusMessage); }); } }
private void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { var text = args.NotificationType.ToString(); var t = args.ToastNotification.Content.ToString(); }
async void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { var alert = new MessageDialog(args.ToastNotification.Content.InnerText, "New Notification Received In App"); await alert.ShowAsync(); }); }
private async void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { String notificationContent = String.Empty; e.Cancel = true; switch (e.NotificationType) { // Badges are not yet supported and will be added in a future version case PushNotificationType.Badge: notificationContent = e.BadgeNotification.Content.GetXml(); break; // Tiles are not yet supported and will be added in a future version case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); break; // The current version of AzureChatr only works via toast notifications case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); XmlDocument toastXml = e.ToastNotification.Content; // Extract the relevant chat item data from the toast notification payload XmlNodeList toastTextAttributes = toastXml.GetElementsByTagName("text"); string username = toastTextAttributes[0].InnerText; string chatline = toastTextAttributes[1].InnerText; string chatdatetime = toastTextAttributes[2].InnerText; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { var chatItem = new ChatItem { Text = chatline, UserName = username }; // Post the new chat item received in the chat window. // IMPORTANT: If you updated the code above to post new chat lines from // the current user immediately in the chat window, you will // end up with duplicates here. You need to filter-out the // current user's chat entries to avoid these duplicates. items.Add(chatItem); ScrollDown(); }); // This is a quick and dirty way to make sure that we don't use speech synthesis // to read the current user's chat lines out loud if (chatline != lastChatline){ ReadText(username + " says: " + chatline); } break; // Raw notifications are not used in this version case PushNotificationType.Raw: notificationContent = e.RawNotification.Content; break; } //e.Cancel = true; }
private async void CurrentChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, RefreshDispatchNoteSummaries); }
static void channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { }
private async void PushChannelOnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { await QmunicateLoggerHolder.Log(QmunicateLogLevel.Debug, "Push notification was received."); }
private static void NotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { try { String notificationContent = String.Empty; switch (args.NotificationType) { case PushNotificationType.Badge: notificationContent = args.BadgeNotification.Content.GetXml(); break; case PushNotificationType.Tile: notificationContent = args.TileNotification.Content.GetXml(); break; case PushNotificationType.Toast: notificationContent = args.ToastNotification.Content.GetXml(); break; case PushNotificationType.Raw: notificationContent = args.RawNotification.Content; break; } ToastMessage message = JsonConvert.DeserializeObject<ToastMessage>(notificationContent); if (App.ApplicationApplicationState == Enums.ApplicationStateType.Active) { args.Cancel = true; try { if (ChatPageViewModel.SelectedFriend.Id != message.FromId) { ToastHelper.DisplayTextToast(ToastTemplateType.ToastImageAndText01, message.FromId, message.Content, message.FromPicture); } } catch (Exception ex) { ex.ToString(); } } else { } ChatPageViewModel chatPageViewModel = ServiceLocator.Current.GetInstance<ChatPageViewModel>(); chatPageViewModel.UpdateMessages(message.FromId, message.Content); } catch (Exception ex) { ex.ToString(); } }
static void pushChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { pushesReceived.Enqueue(args); }
void PrimaryChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { if (args.NotificationType == PushNotificationType.Raw) { var json = Windows.Data.Json.JsonObject.Parse(args.RawNotification.Content); var todoItem = new TodoItem() { Id = (int)json.GetNamedNumber("id"), Complete = json.GetNamedBoolean("complete"), Text = json.GetNamedString("text") }; items.Insert(0, todoItem); } }
private void ChannelShellToastNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e) { Debug.WriteLine("/********************************************************/"); Debug.WriteLine("Incoming Notification: " + DateTime.Now.ToString()); String notificationContent = String.Empty; String type = String.Empty; switch (e.NotificationType) { case PushNotificationType.Badge: notificationContent = e.BadgeNotification.Content.GetXml(); type = "Badge"; break; case PushNotificationType.Tile: notificationContent = e.TileNotification.Content.GetXml(); type = "Tile"; break; case PushNotificationType.Toast: notificationContent = e.ToastNotification.Content.GetXml(); type = "Toast"; break; case PushNotificationType.Raw: notificationContent = e.RawNotification.Content; type = "Raw"; break; } Debug.WriteLine("Received {0} notification", type); Debug.WriteLine("Notification content: " + notificationContent); CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { try { _pushContent = notificationContent; PushAccepted(); var alert = new MessageDialog("Notification content: " + notificationContent, type + " received"); alert.ShowAsync(); } catch (Exception ex) { //Noting todo here } }); Debug.WriteLine("/********************************************************/"); }
/// <summary> /// Handle push notifications /// </summary> /// <param name="sender"></param> /// <param name="args"></param> async void RegisterPushNotifications_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { if (args.NotificationType == PushNotificationType.Raw) { var voteNotification = JObject.Parse(args.RawNotification.Content).ToObject<RawVoteNotification>(); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // Update the options collection with the new vote number var optionToUpdate = App.pvm.Items.Single(o => o.Id == voteNotification.OptionId); optionToUpdate.Count = voteNotification.Count; }); } }
private void OnPushNotificationReceivedHandler(PushNotificationChannel sender, WindowsPushNotificationReceivedEventArgs e) { XmlDocument content = null; if (e.NotificationType == PushNotificationType.Toast && (content = e.ToastNotification?.Content) != null) { AppCenterLog.Debug(LogTag, $"Received push notification payload: {content.GetXml()}"); if (ApplicationLifecycleHelper.Instance.IsSuspended) { AppCenterLog.Debug(LogTag, "Application in background. Push callback will be called when user clicks the toast notification."); } else { var pushNotification = ParseAppCenterPush(content); if (pushNotification != null) { e.Cancel = true; PushNotificationReceived?.Invoke(sender, pushNotification); AppCenterLog.Debug(LogTag, "Application in foreground. Intercept push notification and invoke push callback."); } else { AppCenterLog.Debug(LogTag, "Push ignored. It was not sent through App Center."); } } } else { AppCenterLog.Debug(LogTag, $"Push ignored. We only handle Toast notifications but PushNotificationType is '{e.NotificationType}'."); } }