[英]How to prevent launch of UWP app on click of windows toast
I have UWP app which shows a toast.我有显示敬酒的 UWP 应用程序。 On Click of that toast in toast notification center, it always launches the App if the app is not launched.
在 toast 通知中心单击该 toast 时,如果未启动应用程序,它将始终启动应用程序。 I don't want that.
我不想要那个。 My toast are purely for information purpose to show message to the user.
我的吐司纯粹是为了向用户显示信息的信息。 On click of the toast, it should be dismissed.
单击吐司时,应将其关闭。 It should not launch the app.
它不应该启动应用程序。
Earlier, I had impression that if we give Launch parameter in toast, then only it should launch the app but looks like Launch is irrelevant.早些时候,我的印象是,如果我们在 toast 中提供 Launch 参数,那么只有它应该启动应用程序,但看起来 Launch 是无关紧要的。 It simply launch the app the on click of toast body.
它只需单击吐司主体即可启动应用程序。
I want to prevent launch of app on click of Toast.我想阻止点击 Toast 时启动应用程序。
I have tried following option我试过以下选项
protected override void OnActivated(IActivatedEventArgs args)
{
if( args is ToastNotificationActivatedEventArgs)
{
if(args.Kind == ActivationKind.ToastNotification)
{
Application.Current.Exit();
}
}
}
but this will launch the app and then close the app.但这将启动应用程序,然后关闭应用程序。 It will show the splash screen and user will see abrupt app close.
它将显示启动屏幕,用户将看到应用程序突然关闭。 Moreover, it will close the original working app if app was already launched which I don't want.
此外,如果我不想要的应用程序已经启动,它将关闭原始工作应用程序。
UWP can set the notification active type when sending a notification: UWP 可以在发送通知时设置通知活动类型:
var content = new ToastContent
{
Launch = "...",
ActivationType = ToastActivationType.Background,
Visual = new ToastVisual()
{
...
}
};
var notifier = ToastNotificationManager.CreateToastNotifier();
var notification = new ToastNotification(content.GetXml());
notifier.Show(notification);
After the ActivationType
is set to ToastActivationType.Background
, the application will call the registered background task to process the corresponding content instead of starting the foreground app. ActivationType
设置为ToastActivationType.Background
后,应用程序将调用注册的后台任务来处理相应的内容,而不是启动前台应用程序。
For detailed information about background notifications, you can refer to these documents:有关后台通知的详细信息,您可以参考以下文档:
To use type to represent ToastContent
, you need to install the Microsoft.Toolkit.Uwp.Notifications
nuget package要使用 type 来表示
ToastContent
,您需要安装Microsoft.Toolkit.Uwp.Notifications
nuget package
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.