bug: (messaging) `notificationReceived` fires only for the last message received while the app is killed
See original GitHub issuePlugin(s):
“@capacitor-firebase/messaging”: “^1.1.0”
Platform(s):
Android
Current behavior:
If a data-only notification is received while the app is killed or the device is in doze, the notficationRecieved
listener event does not fire. When the app is opened the next time, the listener fires only for the last message recieved while the app was killed. Every other message is dropped.
Expected behavior:
Code given to the listener should be executed regardless of doze or killed app. Documentation states If the app is in the background, then this listener is only called on data push notifications., but does not make any statement about the app being killed.
Steps to reproduce:
Add listener and send data-only notification to device while app is killed:
FirebaseMessaging.addListener('notificationReceived', event => {
console.log("Notification recieved: ", event); //fires if message is recieved while app in foreground or background
if(event.notification.data?.payload){ //but not if app is killed
//do something traceable which doesn't need console
//for example, write a small file with messageid as filename
}
});
message:
token: "notificationtoken",
data: {
payload: "messagePayload"
},
android: {
priority: "high"
}
Capacitor doctor:
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 4.3.0
@capacitor/core: 4.3.0
@capacitor/android: 4.3.0
@capacitor/ios: 4.3.0
Installed Dependencies:
@capacitor/cli: 4.1.0
@capacitor/core: 4.2.0
@capacitor/ios: 4.2.0
@capacitor/android: 4.2.0
[success] Android looking great! 👌
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top GitHub Comments
This might be a bit off-topic, but for anyone passing here on the hunt for a solution to my problem, adding your own FirebaseMessagingService extender doesn’t play well with capacitor either. I’ve written about that here: https://github.com/ionic-team/capacitor-plugins/issues/1211#issue-1393872221
Just for the sake of being thorough: I just tested the behavior in a production (non-debug) app via internal testing track on google play.
I did this test because I learned that push notifications allegedly have different behavior in debug vs production and also Android is said to kill services associated with an app on close if the app is debug.