Thought
Thought

Reputation: 5846

Managing toast notifications in windows store app 8.1

On a windows 8.1 store app project i want be able to receive toast notifications and then managed the info of them inside my app.

So far i have a nodeJS server that sends the toast notifications and its working well.

What i want to know is: first, how i can handle the event of receiving the notifications, and second, if there is a way of opening the app in diferent pages, when i click the toast notification on windows, depending on what toast i get, for example if i get a toast saying "Hello" i would click on it and the app would open on hello.xaml page, and if i had one saying "Goodbye" i would open the app in the page goodbye.xaml.

this is what i send in nodejs

wns.send({
    channelURI: 'https://db5.notify.windows.com/?token=ABCD',
    payload: '<toast launch="launch_arguments">'+
    '<visual>'+
    '<binding template="ToastText03">'+
    '<text id="1">Notification - ' + date.toDateString().replace(/T/, ' ').replace(/\..+/, '')+ ' ' + date.getHours() + ':'+date.getMinutes() + '.</text>'+
    '<text id="1">msg 123 test 456.</text>'+
    '<text id="1">bla bla bla bla</text>'+
    '</binding>'+
    '</visual>'+
    '</toast>',
    type: 'toast'
});

Upvotes: 0

Views: 690

Answers (1)

Nasser AlNasser
Nasser AlNasser

Reputation: 1775

Here's a good topic about how to handle the Toast Notification :

http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/09/quickstart-sending-a-local-toast-notification-and-handling-activations-from-it-windows-10.aspx

And here's a very good article about the 'Interactive Toast Notification' : http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10.aspx

If you want it for windows 8.1, here's a good guidelines :

https://msdn.microsoft.com/en-us/library/windows/apps/hh761462.aspx https://msdn.microsoft.com/en-us/library/windows/apps/hh465391.aspx

UPDATE 1 :

You can use the launch arguments to send all data you want, not just the params .. i.e.: see "launch=.."

wns.send({
    channelURI: 'https://db5.notify.windows.com/?token=ABCD',
    payload: '<toast launch="{\"params\":\"launch_arguments\",\"text\":\"Notification \",\"text_1\":\"msg 123 test 456\"}">'+
    '<visual>'+
    '<binding template="ToastText03">'+
    '<text id="1">Notification - ' + date.toDateString().replace(/T/, ' ').replace(/\..+/, '')+ ' ' + date.getHours() + ':'+date.getMinutes() + '.</text>'+
    '<text id="1">msg 123 test 456.</text>'+
    '<text id="1">bla bla bla bla</text>'+
    '</binding>'+
    '</visual>'+
    '</toast>',
    type: 'toast'
});

You can edit this :

"{\"params\":\"launch_arguments\",\"text\":\"Notification \",\"text_1\":\"msg 123 test 456\"}"

And, you can easily read that in your App.cs by un-json'ing it ...

Ref: https://msdn.microsoft.com/en-us/library/hh868212.aspx

UPDATE 2:

You can use your own format, not json .. I mean : param1:[val1],param2:[val2].. etc and you can do some Regex to un-format it :-)

Upvotes: 1

Related Questions