locked
Receive Raw Push Notifications on Windows Phone 8.1 Silverlight App RRS feed

  • Question

  • I want to receive the raw notifications on my Windows Phone 8.1 silverlight app. In last 3 days I spent too much time on reading about the same but no luck.

    I'm able to create a channel and register to the hub. See following code:

    PushNotificationChannel channel = null;
    
     private async void InitNotificationsAsync()
            {
                channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
                
               
    
                var hub = new NotificationHub("hub",
                    "Endpoint=sb://KKK.servicebus.windows.net/;SharedAccessKeyName=DefaultListen..........");
    
    
                var result = await hub.RegisterNativeAsync(channel.Uri, new string[] { "device-878" });
    
                if (result.RegistrationId != null)
                {
                    channel.PushNotificationReceived += OnPushNotification;               
                    
                }
            }
    
    
    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;
                }
    
                e.Cancel = true;
            }

    Unfortunately OnPushNotification is not receiving the notifications.

    I want to receive the notifications when the app is running in front and back.

    Thanks

    Kapil

    Tuesday, June 23, 2015 6:51 PM

Answers

  • Hi Sateesh,

    Thanks for your reply.

    I want the notification in both states while app is running or not. As suggested I integrated the Background task and still not receiving the notifications.

    I have a portal to send the notifications and raw notification are sending to mu device. Here I missed an important step, my app is not registered on the Windows Store. This is the biggest thing I missed. Finally I asked my client to register the app. Then I'll try to receive the notifications.

    Will contact you here if I need any help.

    Well thanks! again :)

    Kapil


    Thursday, June 25, 2015 8:30 AM

All replies

  • Hi,

    Your code looks good. You should be able to receive notifications if the app is running. Are you trying debug send from Azure portal?  We have a bug in debug send in azure portal. Could you try sending notification through NotificationHub sdk directly. Something like this.

      NotificationHubClient client = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://KKK.servicebus.windows.net/;SharedAccessKeyName=DefaultListen..........", "hub");

                WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();

                wnsHeaderCollection.Add("X-WNS-Type", @"wns/raw");

    const string body = "Hi there !!";

                client.SendNotificationAsync(new WindowsNotification(body, wnsHeaderCollection)).Wait();

    Raw notifications will be received only if the app is running. If you want to receive raw notification even if’s app is running background, you have do it through “background tasks”.

    Please refer this msdn document: https://msdn.microsoft.com/en-us/library/windows/apps/jj676791.aspx#bg_tasks

    Thanks,
    Sateesh


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Wednesday, June 24, 2015 9:06 PM
  • Hi Sateesh,

    Thanks for your reply.

    I want the notification in both states while app is running or not. As suggested I integrated the Background task and still not receiving the notifications.

    I have a portal to send the notifications and raw notification are sending to mu device. Here I missed an important step, my app is not registered on the Windows Store. This is the biggest thing I missed. Finally I asked my client to register the app. Then I'll try to receive the notifications.

    Will contact you here if I need any help.

    Well thanks! again :)

    Kapil


    Thursday, June 25, 2015 8:30 AM