0

My app receives toast from PHP using WNS server. Now I want to perform some actions when clicking on toast as listed below. When the app is not active - the user should redirect to a page on the app "ShowPage". When the app is active - the toast should show two buttons "Show" and "Cancel". When clicking on Show button app should redirect to "ShowPage"

My current toast from PHP is

 $toastMessage= '<?xml version="1.0" encoding="utf-8"?>'.
 '<toast launch="">'.
 '<visual baseUri="">'.
    '<binding template="ToastGeneric">'.
       '<text>'.$subtitle.'</text>'.
    '</binding>'.
'</visual>'.
'<actions />'.
'</toast>';

And I'm calling below function on App.xaml.cs

 private async void RegisterEngagementNotification()
    {
        StoreServicesEngagementManager engagementManager = StoreServicesEngagementManager.GetDefault();
        await engagementManager.RegisterNotificationChannelAsync();
    }
ucMedia
  • 4,105
  • 4
  • 38
  • 46
nsds
  • 961
  • 4
  • 13
  • 39

2 Answers2

2

Please see the documentation for sending a local toast and handling activation. Everything applies there (other than you're sending the toast from your server, but otherwise adding buttons and handling activation remains the same).

Andrew Leader
  • 975
  • 6
  • 13
  • that link shows button action on foreground and background. but what I need is- I want to show a plain toast when app is not active ..and should show two buttons along with the same toast when app is active. Is it possible? can we add two button programmatically to an existing toast coming from WNS? – nsds Feb 09 '18 at 09:16
  • Yep, just add those buttons to your toast XML from the server. The main toast content docs have XML examples of the payload with buttons: https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts#buttons Download the Notifications Visualizer from the store too, that'll help you see how the XML works. – Andrew Leader Feb 10 '18 at 16:05
1

I saw that you're using StoreServicesEngagementManager APIs, then I know you're sending toast notification from windows developer dashboard. So, if you want to your toast contains two buttons, you would need to add actions like the following:

enter image description here

enter image description here

Then, in your "App.xaml.cs" file, you would need to add some code to handle this option in OnActivated.

protected override void OnActivated(IActivatedEventArgs args)
{
    Frame rootFrame = Window.Current.Content as Frame;
    if (rootFrame == null)
    {
        rootFrame = new Frame();
    }
    base.OnActivated(args);
    var toastActivationArgs = args as ToastNotificationActivatedEventArgs;
    if (toastActivationArgs.Argument =="ShowPage")
    {
        rootFrame.Navigate(typeof(ShowPage));
    }
}
Xie Steven
  • 8,544
  • 1
  • 9
  • 23