I'm developing an Android / Windows application which need to alert the user when a timer times out. On Windows side i'm facing a issue where the notification on system tray doesn't pops out. I followed a bunch of examples over the internet with no luck. Some of them suggested to use the communitytoolkit.winui.notifications, others to follow the github project https://github.com/davidortinau/WeatherTwentyOne
Thanks in advance. Paolo
Below you can see the code that should show up the notification:
using Microsoft.Toolkit.Uwp.Notifications;
using WeatherTwentyOne.Services;
namespace WeatherTwentyOne.WinUI;
public class NotificationService : INotificationService
{
public void ShowNotification(string title, string body)
{
new ToastContentBuilder()
.AddToastActivationInfo(null, ToastActivationType.Foreground)
.AddAppLogoOverride(new Uri("ms-appx:///Assets/dotnet_bot.png"))
.AddText(title, hintStyle: AdaptiveTextStyle.Header)
.AddText(body, hintStyle: AdaptiveTextStyle.Body)
.Show();
}
}
No errors, no notifications either... Someone knows if there's any other solution i can try ?
Toasts are timed reminders that appear at the bottom of the screen. It provides a custom notification time, which can be run in the background. You can check the official documentation (App notification content) for more information.
For some usage methods, you can refer to the answer in the thread (How to use Toast Notifications with .Net Maui).