Search code examples
pythonnotificationswindows-runtime

Python winrt how to get notification listener permission?


How is it possible to get needed permission for a notification listener from winrt in python? The following code immediately returns "denied" without any sort of windows prompt showing up:

import asyncio
import winrt.windows.ui.notifications.management as management

async def main():
    listener = management.UserNotificationListener.current
    access_result = await listener.request_access_async()
    print(access_result) #prints 2: denied

if __name__ == "__main__":
    asyncio.run(main())

Naturally then it is impossible to do anything useful with the notification listener which is a problem.

I ran this code from cmd with python 3.11.4 and winrt 2.0.0b2

The docs mention adding the permission to the manifest for c# apps, but how would this work for winrt-python?


Solution

  • Turns out this maybe should have been over on another stack exchange because the solution was indeed just finding the windows setting buried in the menu: Privacy > Notifications > User notification access

    enter image description here

    You have to evidently turn on the option to allow you to turn on the feature (created by the department of redundancy department I'm sure).