You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to implement a local notification in MAUI on the Windows platform. For this I have used the description of gurrenm3 on the Github (https://github.com/gurrenm3/Toast-Notifications-with-.Net-Maui?tab=readme-ov-file ). This works well with sending a notification, but it doesn't work when the Windows app is opened via the notification, because then I can't get to the argument.
I could also use the notification this way, but it is really stupid for the user if he has to search for his entry in the open app himself. My idea is to pass a parameter (argument) when creating the notification, which I do with
(Of course, the number “9813” is then a variable.)
If I then want to read the argument when opening the app according to gurrenm3 and his instructions, then this must happen in the Platforms\Windows\ App.xaml.cs like this:
public partial class App : MauiWinUIApplication
{
public Action<string> ShowPopup { get; set; }
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
// need to add this because otherwise setting background activation does nothing.
ToastNotificationManagerCompat.OnActivated += (notificationArgs) =>
{
// this will run everytime ToastNotification.Activated is called,
// regardless of what toast is clicked and what element is clicked on.
// Works for all types of ToastActivationType so long as the Windows app manifest
// has been updated to support ToastNotifications.
// you can check your args here, however I'll be doing mine below to keep it cleaner.
// With so many ToastNotifications it would be messy to check all of them here.
Debug.WriteLine($"A ToastNotification was just activated! Arguments: {notificationArgs.Argument}");
// using the code below to show a popup from MainPage, saying that the toast itself was clicked.
if (notificationArgs.Argument.Contains("action=toastClicked"))
ShowPopup?.Invoke("The Toast was clicked!");
};
}
The problem here is that this code is not run at all when the app is opened from the notification:
ToastNotificationManagerCompat.OnActivated += (notificationArgs) =>
{
// you don't need to put anything here if you don't want to.
// You just need to subscribe to it in your app
};
I then checked the Microsoft documentation step by step. The first part of the documentation is sending the notification and that works:
The second part of the documentation then describes in a very short section how to read the parameters after clicking on the notification in the app. The description is given in three variants:
Here is the most important step 3 (Step 3: Handling activation) with these three options: UWP, Desktop(MSIX) and Desktop (unpackaged). If I want to implement the UWP variant, then the “OnActivated” event is unknown under MAUI. The same applies to the third variant with OnStartup and OnActivated events. Apparently this description refers to WPF apps and not to MAUI.
Ahhh almost forgot, I also asked all AIs for a solution, but only there I don't get anything concrete (probably the data is missing). In forums you can only find this one post, from gurrenm3.
I didn't know what else to try? Or is it because of MAUI that it is not possible to read notification arguments under MAUI? Check please also #5945 .
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Description
Hello MAUI development team and contributors,
I am trying to implement a local notification in MAUI on the Windows platform. For this I have used the description of gurrenm3 on the Github (https://github.com/gurrenm3/Toast-Notifications-with-.Net-Maui?tab=readme-ov-file ). This works well with sending a notification, but it doesn't work when the Windows app is opened via the notification, because then I can't get to the argument.
I could also use the notification this way, but it is really stupid for the user if he has to search for his entry in the open app himself. My idea is to pass a parameter (argument) when creating the notification, which I do with
(Of course, the number “9813” is then a variable.)
If I then want to read the argument when opening the app according to gurrenm3 and his instructions, then this must happen in the Platforms\Windows\ App.xaml.cs like this:
The problem here is that this code is not run at all when the app is opened from the notification:
I then checked the Microsoft documentation step by step. The first part of the documentation is sending the notification and that works:
https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/adaptive-interactive-toasts?tabs=appsdk
The second part of the documentation then describes in a very short section how to read the parameters after clicking on the notification in the app. The description is given in three variants:
https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=uwp
Here is the most important step 3 (Step 3: Handling activation) with these three options: UWP, Desktop(MSIX) and Desktop (unpackaged). If I want to implement the UWP variant, then the “OnActivated” event is unknown under MAUI. The same applies to the third variant with OnStartup and OnActivated events. Apparently this description refers to WPF apps and not to MAUI.
Ahhh almost forgot, I also asked all AIs for a solution, but only there I don't get anything concrete (probably the data is missing). In forums you can only find this one post, from gurrenm3.
I didn't know what else to try? Or is it because of MAUI that it is not possible to read notification arguments under MAUI? Check please also #5945 .
I would be very grateful for any information.
Regards
pc
Steps to Reproduce
Link to public reproduction project repository
https://github.com/gurrenm3/Toast-Notifications-with-.Net-Maui
Version with bug
9.0.0-rc.1.24453.9
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
8.0.82 SR8.2
Affected platforms
Windows
Affected platform versions
Windows 11
Did you find any workaround?
No
Relevant log output
The text was updated successfully, but these errors were encountered: