2

我的 uwp 应用程序从 php 服务器接收 toast 通知。它有两个操作按钮“查看”和“关闭”。当应用程序当前处于激活状态时,这些按钮可以正常工作。(查看按钮单击重定向到新页面,而关闭按钮单击将不会执行任何操作。)。但是当应用程序处于关闭状态时 - 当用户点击通知的关闭按钮时,应用程序的启动图标就会出现。我怎样才能阻止这个?当用户单击 Dismiss 按钮时,我想关闭通知。

 $toastMessage= '<toast launch="app-defined-string">'.
 '<visual>'.
'<binding template="ToastGeneric">'.
  '<text>'.$title.'</text>'.
  '<text>'.$subtitle.'</text>'.
  '</binding>'.
 '</visual>'.
'<audio src="ms-winsoundevent:Notification.SMS"  />'.
'<actions>'.
'<action activationType="foreground" content="View"  arguments="viewdetails"/>'.
 '<action content="Dismiss" arguments="later"/>'.
 '</actions>'.  
  '</toast>';

protected override void OnActivated(IActivatedEventArgs args)
    {
       if (args.Kind == ActivationKind.ToastNotification)
        {
            var toastArgs = args as ToastNotificationActivatedEventArgs;
            var arguments = toastArgs.Argument;

            if (arguments == "viewdetails" || arguments== "app-defined-string")
            {
                Frame rootFrame = Window.Current.Content as Frame;
                if (rootFrame == null)
                {
                    rootFrame = new Frame();
                    Window.Current.Content = rootFrame;
                }
                rootFrame.Navigate(typeof(PushNotificationPage));
                Window.Current.Activate();
            }
        }
    }
4

1 回答 1

2

Toast 内容文档描述了如何在 snooze/dismiss 部分添加关闭按钮:https ://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-敬酒#snoozedismiss

<action activationType="system" arguments="dismiss" content=""/>

基本上,将activationType 设置为system 并将参数设置为dismiss。将内容设置为空字符串,将自动使用本地化的关闭文本。

于 2018-02-12T06:24:10.383 回答