How to read notifications coming to Windows with C#

hüseyin yılmaz 0 Reputation points
2023-10-27T10:46:51.7233333+00:00

for example; I want to read notifications coming from Facebook, WhatsApp, browser or any application with C#.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,988 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,576 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,124 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Boris 80 Reputation points
    2023-11-05T12:42:53.7566667+00:00

    To read notifications from other applications in Windows 10, you can use the UserNotificationListener class. However, it’s important to note that this class can only read notifications from the current application. It’s not possible to read notifications from other applications due to privacy and security reasons.

    https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/notification-listener

    0 comments No comments

  2. hellih 0 Reputation points
    2023-12-07T05:47:46.5+00:00

    Create a new C# console application or open an existing one.

    Ensure that you have the necessary references added to your project. Right-click on your project in Visual Studio, choose "Manage NuGet Packages," and search for and install the "Windows Community Toolkit" package. Subscribe to the Notification Activated event:

    Add the following using statement at the top of your code file:

    using Windows.UI.Notifications;

    In your Main method, subscribe to the ToastNotificationManagerCompat.ToastNotificationActivated event:

    ToastNotificationManagerCompat.ToastNotificationActivated += ToastNotificationActivated;

    Implement the event handler:

    Define the ToastNotificationActivated method to handle the notifications: Run the application and wait for notifications:

    Run your C# application and keep it running.

    Receive notifications from the desired applications, such as Facebook or WhatsApp. on your Windows system.

    When a notification is triggered, the ToastNotificationActivated method will be called, and you can access the notification content and handle it as needed.

    private static void ToastNotificationActivated(ToastNotificationActivatedEventArgsCompat e)
    {
        // Handle the notification here
        // You can access the notification content using e.Argument or e.UserInput
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.