【问题标题】:Detect the button click of the Toast notification in UWP检测 UWP 中 Toast 通知的按钮点击
【发布时间】:2017-03-01 13:46:54
【问题描述】:

我的 UWP 应用程序将发送两种不同类型的通知,即通用通知和提醒 Toast。在通用吐司中,我有两个按钮。一个按钮将启动 URL,另一个按钮将启动设置页面。在第二种类型中,我有贪睡按钮。我想检测 toast 通知的按钮点击。

【问题讨论】:

    标签: uwp win-universal-app


    【解决方案1】:

    您可以在通知的元素内定义 arguments 属性。在此之后,您可以阅读应用程序的 OnActivated 中的参数。

    例如:

    1) 通知:

     <actions>
        <action content="launch" arguments="launch"  />
        <action content="settings" arguments="settings" />
      </actions>
    

    2) 应用内的代码:

    async protected override void OnActivated(IActivatedEventArgs args)
    {
        //Find out if this is activated from a toast;
        If (args.Kind == ActivationKind.ToastNotification)
        {
            var toastArgs = args as ToastNotificationActivatedEventArgs;
            var arguments = toastArgs.Arguments;
        //...
    

    这里有一些很好的资源:

    Adaptive and interactive toast notifications

    MSDN Forums

    Full Sample from GitHub (by Microsoft)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多