[英]how to run code when Microsoft toast notification button is pressed in javascript
I am trying to make a microsoft toast notification that has buttons or so called "actions" in this code i have 3 buttons A,B,C and i want to check if any of them are clicked and if so the run a line of code just for example if A is clicked then run debug.log('A') how can i do that?我正在尝试在此代码中制作一个包含按钮或所谓的“操作”的 Microsoft Toast 通知我有 3 个按钮 A、B、C,我想检查是否单击了它们中的任何一个,如果是,则运行一行代码例如,如果单击 A 然后运行 debug.log('A') 我该怎么做? (im new to visual studio and javascript)
(我是 Visual Studio 和 javascript 的新手)
document.addEventListener('keydown', logKey);
function logKey(e) {
var notifLib = Microsoft.Toolkit.Uwp.Notifications;
var toastContent = new notifLib.ToastContent();
var toastVisual = new notifLib.ToastVisual();
var toastBindingGeneric = new notifLib.ToastBindingGeneric();
var adaptiveText = new notifLib.AdaptiveText();
adaptiveText.text = "Hello World";
toastBindingGeneric.children.push(adaptiveText);
adaptiveText = new notifLib.AdaptiveText();
adaptiveText.text = "This is a simple toast message";
toastBindingGeneric.children.push(adaptiveText);
toastVisual.bindingGeneric = toastBindingGeneric;
toastContent.visual = toastVisual;
var toastActionsCustom = new notifLib.ToastActionsCustom();
var toastButton = new notifLib.ToastButton("a", "action=at&userId=1");
toastButton.activationType = notifLib.ToastActivationType.background;
toastActionsCustom.buttons.push(toastButton);
toastButton = new notifLib.ToastButton("b", "action=b&userId=1");
toastButton.activationType = notifLib.ToastActivationType.background;
toastActionsCustom.buttons.push(toastButton);
toastButton = new notifLib.ToastButton("c", "action=b&userId=1");
toastButton.activationType = notifLib.ToastActivationType.background;
toastActionsCustom.buttons.push(toastButton);
toastContent.actions = toastActionsCustom;
// Create the toast notification
var toastNotif = new Windows.UI.Notifications.ToastNotification(toastContent.getXml());
// And send the notification
Windows.UI.Notifications.ToastNotificationManager.createToastNotifier().show(toastNotif);
};
for UWP applications, when the notification button is pressed, the activated
event of the application will be triggered.对于 UWP 应用程序,当按下通知按钮时,将触发应用程序的
activated
事件。 In javascript, it can be written like this:在 javascript 中可以这样写:
Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (activatedEventArgs) {
if (activatedEventArgs.kind == Windows.ApplicationModel.Activation.ActivationKind.toastNotification) {
console.log(activatedEventArgs.argument);
}
});
If you are using WinJs to build your application, you can find the corresponding code block that handles the click of the Toast notification in the app.onactivated
event in main.js如果你使用 WinJs 构建你的应用程序,你可以在main.js中的
app.onactivated
事件中找到对应的处理 Toast 通知点击的代码块
...
else if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.arguments) {
}
...
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.