-
Notifications
You must be signed in to change notification settings - Fork 283
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
Android 13+ app doesn't trigger on('notification') when clicking notification while app is closed or running in background #288
Comments
Same issue here |
Hi, You can try to put in your payload this |
Thanks @ciuffo81, however, I haven't been able to get it to work even after adding the "click_action". I tried different ways of setting the click_action, first trying to add it to the "notification" property/object, but received an invalid JSON payload error. Here's my code showing all the places I've tried to include the "click_action" property, including the commented out places that caused invalid JSON payload errors:
In looking at this https://firebase.google.com/docs/cloud-messaging/concept-options#notifications, it appears that utilizing the "android.notification.click_action" property is the proper way of doing it, but it has a not effect from my tests. I also looked at the issue you linked to and saw someone had a problem with a missing entry in the manifest, but I've verified my manifest file has the following:
Nothing seems to work. |
Have you been able to find a solution? I am having the exact same issue and none of the suggested solutions work for me. |
No, I haven't found a solution yet. |
I'm experiencing the same issue as well. I've made a few different attempts at a fix (including the example above), but I haven't been able to get it to work. @erisu Would you be able to weigh in on this issue? |
Hi everyone, We use the plugin and everything is working fine for us.
Our Tests included the cases
So everything is working as described in the documentation So here are my questions:
|
Turns out my code was missing "click_action": "com.adobe.phonegap.push.background.MESSAGING_EVENT" I got it working with the following payload:
|
@vlads63 thats good news @redbird19 @ElliotNB do you have new insights? what are your buildetails? |
Hi @ksch10bob, thanks for willing to help out. I use Ionic AppFlow to build my app, and the build details are as follows:
I also use the following Environment overides:
My config.xml file uses:
And uses the following preferences:
My server code that sends the notifications uses the following payload:
The server code utilizes CorePush (https://github.com/andrei-m-code/net-core-push-notifications) to make the call to: https://fcm.googleapis.com/v1/projects/{settings.ProjectId}/messages:send, and POST the serialized payload. Everything works great when the app is open on my Android 13 phone. The on('notfication') event is fired, and I can parse the message and redirect the user to the appropriate place in the app based on the arguments in the "data" properties. But if the app is closed or in the background when the notification is received, clicking the notification will open the app but the on('notification') event is NOT triggered. Unfortunately, I only have my personal Android 13 phone I'm testing with, so I can't be sure if this is exclusively a problem with my phone, which is an Android Moto G Play (XT2413V) phone. Edit: I've now also tested with several Android emulated devices via https://appetize.io (Pixel 8, Pixel 7, Galaxy Tab S7) running Android 13 and 14, and all have the same behavior described above (when app is closed or in background, clicking the received notification opens the app but does NOT trigger the on('notification') event). |
@redbird19 thanks for the information. |
@redbird19
|
@ksch10bob, thanks for taking a look. The Ionic Appflow build stack uses cordova 12.0.0 (so I'm assuming Cordova Android 12.0.0). FYI, Ionic Appflow is sort of the successor to Adobe's PhoneGap Build (or at least the alternative that I chose). When Adobe shutdown PhoneGap Build back in August 2020, I switched over to Ionic Appflow following this migration guide (https://ionic.io/docs/appflow/cookbook/phonegap-build-migration). The migration was pretty painless and only required a handful of mostly minor changes, and they have been pretty good at updating the build stacks to support the latest versions of Cordova. The iOS version of the app works flawlessly, and the Android version is nearly perfect as well, just need to fix this last issue with on('notification') not firing when the app is closed/in-background. I'm not really sure how to simplify the app's code. Everything else seems to be working fine, and no errors are thrown, it's just that the on('notification') event is not fired when the app is closed/in-background. I even connected the phone to Chrome's debugging and added breakpoints, but they just aren't hit. I'll keep trying though. |
I added some more debugging code and after a lot of trial and error finally got the on('Notification') event to fire when the app is closed or in the background! :) You definitely need to add/include the android.notification.click_action property:
However, one oddity I didn't expect is that the data received by the on('Notification') event differs depending on whether the app was open or not. With the app open, the message received looks like this:
But when the notification received when the app is in the background is clicked, the app is opened and the message received by the on('Notification') event looks like this:
Note the lack of "title" and "message" properties in the payload. I think I can work around this by adding the "title" and "message" to the "data" property when sending the notification and then checking the "additionalData" property for the title and/or message when receiving the message in on('notification'). Oh....strangely, I just tried to add the "title" property and "message" to the "data" property when sending, and message received in on('notification') shifted the "title" and "message" properties to the top level
It's still a bit of a mystery to my why the data payload is different, or why I need to send the notification a little differently to get it to work when the app is closed, but at least I got it working now. Thanks for the help! |
@redbird19 thats good news. The FCM SDK behaves differently for foreground and background receiving when using mixed payloads (notification and data payload)
This is standardbehavior documented here |
@ksch10bob, thanks for the help and pointing me to the documentation, good to know! |
FYI, I'm using cordova-plugin-push 4.0.0 and testing with my Android 13 phone.
When the app is closed, or running in background, and a notification is received, clicking the notification will open the app, but not fire the on('notification') event, which prevents the app from automatically redirecting the user to the appropriate location in the app related to the notification. This only seems to affect Android 13+.
FYI, if I have the app open when the notification is received, the app correctly fires the on('notification') event, enabling automatic redirection to the appropriate location.
In iOS, things work perfectly, clicking the notification with the app closed, or running in background, opens the app AND fires the on('notification') event allowing the user to be automatically redirected to the appropriate location in the app.
The text was updated successfully, but these errors were encountered: