2021年2月6日星期六

C# .NET UserNotificationListener element not found

I'm trying to hook into the UserNotificationListener in order to intercept Windows 10 Notifications however I'm unable to hook the event itself nor retrieve the notifications directly without the event. I need this to run in a Winforms application and not UWP application but unfortunately the microsoft docs explain how to do this only for UWP. (https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener)

private async void checkUserNotificationListenerAccess()      {          listener = UserNotificationListener.Current;          UserNotificationListenerAccessStatus accessStatus = await listener.RequestAccessAsync();          try          {              listener.NotificationChanged += Listener_NotificationChanged;              Debug.WriteLine("Listener Hooked");          } catch (Exception e)          {              var access_status = UserNotificationListener.Current.GetAccessStatus();              Debug.WriteLine("Notifications Hook failed");          }      }  

The Exception always fires giving the error "Element not found. (Exception from HRESULT: 0x80070490)". The variable access_status returns "Allowed".

Does anybody have any idea on how to sort this out?

https://stackoverflow.com/questions/66083903/c-sharp-net-usernotificationlistener-element-not-found February 07, 2021 at 10:05AM

没有评论:

发表评论