c# - 如何获取 Windows 10 的内容?UWP/C# 中的通知?
问题描述
我正在尝试获取用户通知中的文本,以及单击通知时发生的操作。我获得了用户阅读它们的权限(使用UserNotificationListener.RequestAccessAsync()
),然后我遍历它们,并将它们添加到 ListView:
private async void getNotificationsAsync()
{
UserNotificationListener listener = UserNotificationListener.Current;
IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
NotificationsList.Items.Clear();
foreach (UserNotification notif in notifs)
{
//Console.WriteLine(notif.AppInfo.DisplayInfo.DisplayName);
NotificationsList.Items.Add(notif.AppInfo.DisplayInfo.DisplayName);
}
}
但我能从UserNotification 类中得到的只是启动应用程序的名称(以及通知发生的时间)。我找不到任何方法来访问UserNotification
课堂上的通知内容。
我正在尝试的可能吗?我使用正确的课程吗?
解决方案
找到了!(总是在我提出问题后发生)。为了后代的缘故,这是答案:
NotificationBinding toastBinding = notif.Notification.Visual.GetBinding(KnownNotificationBindings.ToastGeneric);
if (toastBinding != null)
{
// And then get the text elements from the toast binding
IReadOnlyList<AdaptiveNotificationText> textElements = toastBinding.GetTextElements();
// Treat the first text element as the title text
string titleText = textElements.FirstOrDefault()?.Text;
// We'll treat all subsequent text elements as body text,
// joining them together via newlines.
string bodyText = string.Join("\n", textElements.Skip(1).Select(t => t.Text));
}
推荐阅读
- r - Azure HDInsight 群集中的 HDFS 路径
- javascript - 从另一个文件向命名空间/模块添加函数
- android - 如何在 ARCore 中的另一个门户场景中实现门户场景?
- c - 请问有人能解释一下这个递归代码吗?
- python - python中维基百科页面的内链和外链
- blur - 找不到 UIModalPresentationStyle 枚举值 blurOverFullScreen
- tags - Gitlab 项目标签和 Runner 标签;他们有关系吗?
- compiler-errors - Gnuplot - 误差线
- java - 引起:java.lang.NumberFormatException:对于输入字符串:“?” 对于 cron 工作
- django - 使用 pk 以外的属性识别 Django Rest Framework ModelSerializer ForeignKey