-
-
Notifications
You must be signed in to change notification settings - Fork 7
[Bug] Foreground notifications in Android not working #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I tested the given initialization code with your push notification message and I also don't get a notification while the app is in foreground mode. However, I used the sample app in this repository (which is .NET 8). I can confirm that it works in the sample app.
So, from the library's point of view, everything seems fine. If you provide a small reproduction sample app, I might be able to provide further help. |
I guess this is a bug. Can you try the latest 3.1.x-pre nuget? There is a major fix and a big refactoribg in this build that deals with Android notification handling. |
@goatrodeosoftware can you try the latest stable release 3.1.27 and let me know if this problem still exists? |
Hi Thomas- sorry, I moved on to another library for firebase. |
Hello Thomas, i have the same problem with foreground notification not shown on android 10.0 device.
with the error: System.ArgumentException: 'SetNotificationChannels failed: notificationChannelRequests does not contain any active NotificationChannelRequest with IsDefault=true (Parameter 'notificationChannelRequests')' I see that on your sample app you use o.Android.NotificationChannels = NotificationChannelSamples.GetAll().ToArray(); but because i prefer to not add "sample code" that maybe works i try to downgrade to the previous version 3.0.28 and it run correctly except foreground notification. Is mandatory to set NotificationChannels ? there is a default implementation without adding sample code? I need that user can upgrade the app from the previous one to this one without changing anything on notification and using the default channel (and receive notification using topic) Thanks |
@thomasgalliker I can confirm the issue reported by @REDECODE above. In scope of migrating to .NET 9 I tried to update the plugin from version 3.0.28 to the latest 3.1.27 and encountered with the failure on start:
The issue has disappeared only when I added |
I found the problem. PS: another possible solution is to not set the DefaultNotificationImportance but set the priority correcty when i send the notification from the API in the Data section.
|
Ahh, now I understand what you mean @REDECODE :) Aww, yes. Just to clarify: NotificationReceived event is fired when the Android app runs in foreground AND you do not set the priority to high, correct? That would be how it's designed to work. As soon as you receive a notification with "high priority" the notification popup is also shown when the app runs in foreground mode. One more thing to add: You can also set this as a default behavior in |
The System.ArgumentException 'SetNotificationChannels failed: notificationChannelRequests does not contain any active NotificationChannelRequest with IsDefault=true (Parameter 'notificationChannelRequests') mentioned by @KotM is a different problem. It's actually not a problem, it is absolutely intended. I changed something in the internal design of how notification channels in android are handled. Obviously, many devs struggle with this as it seems to be a not very helpful exception message. I'll check if I can bring back a default notification channel again (if none is created by the dev at startup). |
@KotM the exception regarding 'missing default notification channel' should be gone in latest pre-release (currently 3.2.1-pre). I this version, I always create a default notification channel if none is specified in the Android-specific options ( Feedback is welcome. |
Uh oh!
There was an error while loading. Please reload this page.
Description
I've gone through all the issues on this topic that were closed and tried the steps that solved this issue before; frankly, I'd assume I've missed something and maybe will find a way that the instructions/fix can be clearer and not that there's a legit issue, but nonetheless:
I'm able to receive notifications in the background, but in the foreground I neither get a notification nor is the notification received event raised. I'd ask you to just have a quick look and point me in the right direction rather than doing more work yourself than necessary to get me unstuck.
Steps to Reproduce
I've registered in MauiProgram.CreateMauiApp:
.UseFirebasePushNotifications(o => {
o.Android.NotificationChannels = new NotificationChannelRequest[] { new NotificationChannelRequest() {
ChannelId = "1",
ChannelName = "Name",
Description = "ZZZ",
LockscreenVisibility = NotificationVisibility.Public,
Importance = NotificationImportance.High,
IsDefault = true}
};
})
(both with and without the o=> initialization)
{
"message": {
"token": "{{token}}",
"notification": {
"title": "Notification title",
"body": "Notification body"
},
"data": {
"channel_id": "default",
"priority": "high"
},
"android": {
"priority": "high"
}
}
}
(both with and without the android element)
Then wired it up in App.xaml.cs:
protected override async void OnStart()
{
await firebasePushNotification.RegisterForPushNotificationsAsync();
firebasePushNotification.TokenRefreshed += FirebasePushNotification_TokenRefreshed;
firebasePushNotification.NotificationReceived += FirebasePushNotification_NotificationReceived; ;
base.OnStart();
}
Expected Behavior
Actual Behavior
Basic Information
The text was updated successfully, but these errors were encountered: