1

I want to control push notifications (toast) coming from WNS server before it displays on screen..I can do it in Android but can I do it in Windows Phone..??

Stefan Over
  • 5,851
  • 2
  • 35
  • 61
artista_14
  • 674
  • 8
  • 22
  • what type of action you are intending to do? – asitis Feb 10 '16 at 11:31
  • Before toast appears on the screen I want to compare its parameter to some value & if it satisfies the condition then I want to show the notification....Here is the string I am sending through push notification........" + subject + "" + body + " – artista_14 Feb 10 '16 at 13:22

2 Answers2

1

you can use toast notifications in your case. Toast notifications are handled by OS. you can get payload in launch argument at OnLaunched Event of App.

Client sample

Server app, you can use it for testing. You can also use emulator for push testing.

vITs
  • 1,651
  • 12
  • 30
  • The code inside OnLaunched Event will run after app is launched..But before that notification appears on the screen...I don't want that..I want to catch data before notification appears and decide to show it or not..... – artista_14 Feb 10 '16 at 17:07
  • 1
    Then in this case use raw notification. Add background task and in Run add your logic and show own toast there. – vITs Feb 10 '16 at 17:11
  • Accept answer if it helped you.. Cheers! – vITs Feb 11 '16 at 18:05
1

I believe you want a raw notification, this is a notification that your phone handles while the application is running.

When you create your pushchannel you can use the OnPushNotificationRecieved Event to do logic when reciving a notification.

This way your logic will trigger before the notification appears on the screen IF the application is running.

If the application is not running it will be a regular Toast.

Example:

    _channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
    _channel.PushNotificationReceived += OnPushNotificationReceived;

   private void OnPushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
    {
        switch (args.NotificationType)
        {
            case PushNotificationType.Badge:
                this.OnBadgeNotificationReceived(args.BadgeNotification.Content.GetXml());
                break;

            case PushNotificationType.Tile:
                this.OnTileNotificationReceived(args.TileNotification.Content.GetXml());
                break;

            case PushNotificationType.Toast:
                this.OnToastNotificationReceived(args.ToastNotification.Content.GetXml());
                break;

            case PushNotificationType.Raw:
                this.OnRawNotificationReceived(args.RawNotification.Content);
                break;
        }

        args.Cancel = true;
    }

    private void OnBadgeNotificationReceived(string notificationContent)
    {
        // Code when a badge notification is received when app is running
    }

    private void OnTileNotificationReceived(string notificationContent)
    {
        // Code when a tile notification is received when app is running
    }

    private void OnToastNotificationReceived(string notificationContent)
    {
        // Code when a toast notification is received when app is running

        // Show a toast notification programatically

        var xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(notificationContent);
        var toastNotification = new ToastNotification(xmlDocument);

        //toastNotification.SuppressPopup = true;
        ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
    }

    private void OnRawNotificationReceived(string notificationContent)
    {
        // Code when a raw notification is received when app is running
    }
Tobias
  • 73
  • 8
  • I have question where your answer would fir quite well to I think, I will test it later. I only have one additional question compared to your solution. But you could look at my question and get some points :) http://stackoverflow.com/questions/35460872/depending-on-page-viewed-act-on-toast-notification-wp8-1-silverlight-receiving – JTIM Feb 18 '16 at 14:55