Reputation: 9600
I am new to MAUI and am trying to receive push notifications via Firebase in my Android app via Topics.
If I use the device token directly then it works OK, but trying to send via a topic then I don't get any notification at all. I am using Firebase.Admin nuget package. Somewhere I have configured something wrong, but I don't know what and where.
This is my maui app where I create the notification channel.
private void CreateNotificationChannel()
{
var channelId = $"{PackageName}.Devices";
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
var channel = new NotificationChannel(channelId, "Devices", NotificationImportance.Default);
notificationManager.CreateNotificationChannel(channel);
FirebaseCloudMessagingImplementation.ChannelId = channelId;
FirebaseMessaging.Instance.SubscribeToTopic("Devices");
}
I have a simple app which sends the notifications (for testing)
var message = new Message()
{
Data = new Dictionary<string, string>()
{
{"myData", "detail sent in message" },
},
//Token = deviceToken,
Topic = "Devices",
Notification = new Notification()
{
Title = "Test from code",
Body = "Body of message is here"
}
};
As you see, the Topic matches the channel name in the Maui app.
If I change this to use the deviceToken
instead, then it works OK.
I don't get any errors, the client app says that the message was sent OK, so I think it must be an error in the Maui app, but I don't know how to fix the problem
Upvotes: 0
Views: 1304
Reputation: 9600
So I managed to find the issue.
The method CreateNotificationChannel() was part of the Android specification application code.
So I moved this line
FirebaseMessaging.Instance.SubscribeToTopic("Devices");
to a different part of the code (called during application DI is built during application start-up) and then the notification worked also for topics.
Upvotes: 1