Reputation: 83
Anybody have a working program to listen to app notifications on Windows 11? Have tried many solutions using UserNotificationListener with winrt and winsdk, each with an "ALLOWED" access status. Despite that each program returns an OSERROR: WinError Element not found. Here is my current code:
from winrt.windows.ui.notifications.management import UserNotificationListener, UserNotificationListenerAccessStatus
from winrt.windows.ui.notifications import NotificationKinds, KnownNotificationBindings
import asyncio
async def main():
listener = UserNotificationListener.current
accessStatus = await listener.request_access_async()
if accessStatus != UserNotificationListenerAccessStatus.ALLOWED:
print("Access to UserNotificationListener is not allowed.")
exit()
def handler(listener, event):
notification = listener.get_notification(event.user_notification_id)
# get some app info if available
if hasattr(notification, "app_info"):
print("App Name: ", notification.app_info.display_info.display_name)
listener.add_notification_changed(handler)
if __name__ == "__main__":
asyncio.run(main())
This code was from a solution provided in this thread: How can I listen to Windows 10 notifications in Python?
Have also tried the solution posted here with same sort of results: Tried to listen to windows notification but got element not found error
Suspect the errors are resulting either due to special permission requirements that need to be granted for the app or a change in Windows 11. If you have good knowledge of windows or the sdk any help would be greatly appreciated.
Upvotes: 0
Views: 119