Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toast notification in windows 8.1 app

i am facing a weird problem. I am using Windows phone 8.1 silverlight and Windows universal link for toast notification. I am able to get the toast notification in Windows Phone app it is nearly same way in Windows 8.1 as mentioned in the link. But toasts are not comming in Windows 8.1 part.

Steps :-

1 -> I have enabled the Toast from Package.appxmanifest file.

2 -> Then i have added this code in App.Xaml.cs in on_launched event as mentioned

It is showing the registeration successful as mentioned in the link

private async void InitNotificationsAsync()
{
      var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
      var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
      var result = await hub.RegisterNativeAsync(channel.Uri);

                // Displays the registration ID so you know it was successful
      if (result.RegistrationId != null)
      {
           var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
           dialog.Commands.Add(new UICommand("OK"));
       await dialog.ShowAsync();
      }
}

3 -> Now i send the notification from back end(Hub is working in case of phone mpns notification).

public static async void SendNotificationAsync()
{
        NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
        var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>";
        await hub.SendWindowsNativeNotificationAsync(toast);
 }

Question : - Do you guys have a clue why it is not working in Windows 8.1 or what i am missing. This is the simplest example i am going through. Any help is appreciated.

Edit :- This is something interesting.

When i tried to send the notification from azure portal. From DEBUG tab of My-NotificationHub and from here i choose WNS toast then it showing an error.

Error - The token obtained from the token provider is wrong

but when i tried to send MPNS notification then there is no error. as i already mentioned it is working for WP 8.1 silverlight MPNS toast.

What could be the cause of this error ?

like image 785
loop Avatar asked Jul 25 '14 15:07

loop


People also ask

How do I make toast notifications?

Instantiate a Toast objectUse the makeText() method, which takes the following parameters: The application Context . The text that should appear to the user. The duration that the toast should remain on the screen.

How do I show toast notifications in Winforms app?

Start screen application shortcuts are in the %AppData%\Microsoft\Windows\Start Menu\Programs folder, and you need to add a shortcut to this folder to show toast notifications.

What is a Windows toast notification?

A toast notification is a message that your app can construct and deliver to your user while they are not currently inside your app. This quickstart walks you through the steps to create, deliver, and display a Windows 10 or Windows 11 toast notification using rich content and interactive actions.

How do I turn off Windows 8.1 notifications?

Access the Charm Bar on the right side of the screen or Windows Key + C on your keyboard and click on settings, as in. After clicking on Settings, you will click on More PC Settings that shows up in the end, as in. In this step, you will see the PC settings. You click on Notification Option in the left pane, as in.


1 Answers

Toast will not work on simulator, as stated in the MSDN documentation:

Note When testing toast notification code functionality through Microsoft Visual Studio, you must use either the Local Machine or Remote Machine debug setting on a Windows x86, x64, or Windows Runtime machine. You cannot use the Visual Studio Simulator debug function option—your code will compile and run in the Simulator, but the toast will not appear.

Source: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868254.aspx

like image 101
Sean Avatar answered Oct 06 '22 00:10

Sean