Reputation: 666
I'd like to block some of notifications. I can do it when app is in foreground, using the code below:
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
channel.PushNotificationReceived += Channel_PushNotificationReceived;
And later:
private void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
{
if (args?.NotificationType == PushNotificationType.Toast)
{
if (string.IsNullOrWhiteSpace(args.ToastNotification?.Content?.InnerText))
{
args.Cancel = true;
}
}
}
But I have no idea how to do it when app is turned off. I tried Notification Listener, but I get access to notifications only when they're already presented.
My question is, how to block some notifications, when app is in the background?
Upvotes: 0
Views: 82
Reputation: 666
Because I'm using Azure Notification Hub, I can't use Raw Push Notifications. Eventually I added a tag with device family (uwp, android, ios), and send the notification from hub using syntax tag && !uwp
that sends particular notification everywhere but not to uwp.
Upvotes: 0
Reputation: 39082
You could use Raw Push Notifications (see docs). These are special kind of notifications with no associated UI, but you can create a background task that is triggered whenever such notification arrives. In this task you can then decide if you want the notification to be displayed and in such case create and show the notification directly in code.
Upvotes: 1