ToastNotification: Unable to handle Toast Activation (user interaction)

Emil

Member
Joined
Aug 24, 2021
Messages
6
Programming Experience
Beginner
Hello,

i have problems handling/evaluating the user reaction (button pressed...) from a ToastNotification.

Tried this code:

Code:
        ToastContentBuilder tcb = new ToastContentBuilder();
        tcb.AddArgument("action", "viewConversation");
        tcb.AddArgument("conversationId", 9813);
        tcb.AddText("Installation will be executed in 2 minutes");
        tcb.AddAppLogoOverride(new Uri(PROGRAM_PATH + "LDNotifyIcon.png"), ToastGenericAppLogoCrop.Circle);
        tcb.AddHeroImage(new Uri(PROGRAM_PATH + "LDNotifyHero.png"));
        tcb.AddToastInput(new ToastSelectionBox("time")
        {
            DefaultSelectionBoxItemId = "60",
            Items =
             {
            new ToastSelectionBoxItem("1", "1 minute"),
            new ToastSelectionBoxItem("5", "5 minutes"),
            new ToastSelectionBoxItem("10", "10 minutes"),
            new ToastSelectionBoxItem("60", "1 hour"),
            new ToastSelectionBoxItem("240", "4 hours")
            //new ToastSelectionBoxItem("1440", "1 day")
             }
        });
        tcb.AddButton(new ToastButton()
            .SetContent("Start now")
            .AddArgument("action", "startNow")
            .SetBackgroundActivation());
        tcb.AddButton(new ToastButton()
            .SetContent("Snooze")
            .AddArgument("action", "snooze")
            .SetBackgroundActivation());
        tcb.SetToastScenario(ToastScenario.Reminder);
        tcb.GetToastContent();
        toast = new ToastNotification(tcb.GetXml());
        toast.Activated += HandleToastActivation;
        toast.Tag = "RebootNotifier";
        ToastNotificationManager.CreateToastNotifier().Show(toast);
                
        private static void HandleToastActivation(ToastNotification sender, object args)
        {
            Log("HandleToastActivation reached"); // writing to Logfile
        }

The toast shows up, but when i press "Snooze", the void "HandleToastActivation" is never reached.

Alternatively i tried in the Startup function:

Code:
        ToastNotificationManagerCompat.OnActivated += toastArgs =>
        {
            // Obtain the arguments from the notification
            ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
            string strAction = args.Get("action");

            // Obtain any user input (text boxes, menu selections) from the notification
            ValueSet userInput = toastArgs.UserInput;
            userInput.TryGetValue("time", out object oTime);
            ...
        }

Again - the code lines are never reached.

I have a wpf application, included a packaging project, finally the project will be published as an MXIS Installation package file.

Could anyone please help me how i can get/handle the user input from the toast notification?
That would be great
Thanks a lot in advance !
 
Back
Top Bottom