Windows Toast 通知,COM 不工作

Windows Toast Notification, COM Not working

我一直致力于满足以下要求的 Toast 通知。

所以我创建了一个示例 UWP 应用程序。它适用于前景和背景。但是当我从 powershell 中创建吐司时。通知未激活。

我遵循了 - https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast-desktop?tabs=msix-sparse

中的步骤

我也验证了并且可以在注册表中看到 GUID。

回购示例应用程序 - https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/send-local-toast 您需要添加一个 nuget 包才能使其工作 - Microsoft.Toolkit.Uwp.Notifications

Powershell 脚本 -


[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null

$APP_ID = 'DF068783-F662-4A13-8BFC-F8BC1E53F4E6'

$template = @"
<toast activationType="protocol" launch="DF068783-F662-4A13-8BFC-F8BC1E53F4E6\WinFormSampleAppActivator" duration="short">
    <visual>
        <binding template="ToastGeneric">
            
            <image placement="appLogoOverride" src="C:\Users\dksil\OneDrive\Desktop\Go\s.jpg" />
            
            
            <text><![CDATA[Test]]></text>
            
            
            <text><![CDATA[some test]]></text>
            
        </binding>
    </visual>
    
    <audio src="ms-winsoundevent:Notification.Default" loop="false" />
    
    
    <actions>
        
        <action activationType="protocol" content="I'm a button" arguments="DF068783-F662-4A13-8BFC-F8BC1E53F4E6" />
        
    </actions>
    
</toast>
"@

$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($template)
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID).Show($toast)
    

感谢帮助!!!

在 google 上花费数小时并尝试了很多东西之后。我发现问题出在 Power shell 脚本上。

下面的 PS 脚本有效。如果你能说出为什么这个有效而不是上面的,那就太好了。

$null = [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
$null = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]

$App = "af954980-b64d-4c13-858f-614bcbeb295e_304r6e67w7w2y!App"

[xml]$Toast = @"
<toast duration="short">
    <visual>
    <binding template="ToastGeneric">
        <image placement="appLogoOverride" src="C:\Users\dksil\OneDrive\Desktop\Go\s.jpg" />
        <text>Hello</text>
        <text>Deepak Dash</text>
    </binding>
    </visual>
    <audio src="ms-winsoundevent:Notification.Default" loop="false" />
    <actions>
        
        <action activationType="Protocol" content="I'm a button" arguments="C:\Users\dksil\OneDrive\Desktop\Go" />
        
    </actions>
</toast>
"@


# Load the notification into the required format
$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument
$ToastXml.LoadXml($Toast.OuterXml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($App).Show($ToastXml)

注意 - 我还尝试将 $App 设置为“af954980-b64d-4c13-858f-614bcbeb295e_304r6e67w7w2y!App”。这也不适用于之前的 PS 脚本。

谢谢, 迪帕克短跑