怎么可以获取电脑右下角通知里面的通知信息呢?
想要根据通知信息来判断执行某个动作
quicker里没有这方面的功能。
参考AI的回复。
可以。Windows 10/11 官方提供了 UserNotificationListener,能够读取通知中心里的通知,包括其他应用发出的通知。
UserNotificationListener
基本流程是:
userNotificationListener
GetNotificationsAsync()
NotificationChanged
C# 核心代码大致如下:
using Windows.UI.Notifications; using Windows.UI.Notifications.Management; var listener = UserNotificationListener.Current; // 必须在 UI 线程调用,会弹出系统授权界面 var status = await listener.RequestAccessAsync(); if (status != UserNotificationListenerAccessStatus.Allowed) { return; } // 读取当前通知中心中仍然存在的 Toast 通知 var notifications = await listener.GetNotificationsAsync(NotificationKinds.Toast); foreach (var notification in notifications) { string appName = notification.AppInfo?.DisplayInfo?.DisplayName ?? ""; DateTimeOffset createdAt = notification.CreationTime; var binding = notification.Notification.Visual .GetBinding(KnownNotificationBindings.ToastGeneric); string[] texts = binding? .GetTextElements() .Select(x => x.Text) .ToArray() ?? []; Console.WriteLine($"应用:{appName}"); Console.WriteLine($"时间:{createdAt}"); Console.WriteLine($"内容:{string.Join(" | ", texts)}"); }
监听变化:
listener.NotificationChanged += async (_, args) => { // 回调可能不在 UI 线程 var current = await listener.GetNotificationsAsync( NotificationKinds.Toast); // 建议按 notification.Id 建立快照, // 对比前后集合判断新增和删除 };
应用清单需要声明:
<Package xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap3"> <Capabilities> <uap3:Capability Name="userNotificationListener" /> </Capabilities> </Package>
几个重要限制:
ToastNotifications
微软官方文档:Notification listener、UserNotificationListener、清单能力声明。
如果目标是让 Quicker 获取这些通知,技术上可行,但首先要核实 Quicker 当前安装包是否具备合适的包身份和清单能力;否则可能需要增加一个打包的通知代理进程,再把通知转交给 Quicker。