简体   繁体   English

如何防止在单击 windows 吐司时启动 UWP 应用程序

[英]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.

相关问题 启动 UWP 应用程序表单 Toast 按钮单击 Windows 操作中心 - Launch a UWP application form toast button click in windows action center 如何将字符串传递给UWP应用程序并从Windows窗体应用程序启动它 - How to pass string to UWP app and launch it from a Windows Forms app 如何使用 C# 从 Windows 窗体启动 UWP 应用程序 - How to launch UWP app from windows forms using C# 如何使用 UWP 应用检测由另一个应用触发的 Windows 10 Toast 通知 - How to detect windows 10 toast notification triggered by another app using a UWP app 如何在UWP App中创建信息丰富的Toast通知 - How to create informative toast notification in UWP App 了解Toast推送通知以及如何在其上显示文本并通过按它们启动应用程序。 Windows Phone 8.1 - Understanding Toast push notifications and how to display text on them and launch app by pressing on them. Windows Phone 8.1 如何在通用Windows平台(UWP)应用中用鼠标单击移动文本框 - How to move a textbox with mouse click in Universal Windows Platform (UWP) app 如何在浏览器中单击按钮启动Windows通用应用程序? - How to launch my windows universal app with button click in browser? 从我的UWP应用启动默认的Microsoft Windows Weather应用 - Launch the default microsoft windows weather app from my UWP App 如何在后台启动和运行UWP应用 - How to launch and run a UWP app in the background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM