Push plugin seems to work, but push notifications never arrive to any Android device
See original GitHub issueBug Report
Capacitor Version
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 2.2.0
@capacitor/core: 2.2.0
@capacitor/android: 2.2.0
@capacitor/electron: 2.2.0
@capacitor/ios: 2.2.0
Installed Dependencies:
@capacitor/electron not installed
@capacitor/cli 2.2.0
@capacitor/android 2.2.0
@capacitor/core 2.2.0
@capacitor/ios 2.2.0
[success] Android looking great! �
[error] Xcode is not installed
Platform(s)
Android (didn’t test iOS yet).
Current Behavior
Capacitor correctly installs into my project, and the PushNotifications plugin seems to work fine: it correctly gets a user token that also gets correctly stored in my backend. Thing is, when I send the actual push, it won’t ever arrive to my device. Tested in two different devices (Xiaomi Pocophone F1, and a Huawei P Smart+).
Expected Behavior
These devices should be receiving the pushes correctly — which they don’t.
Code Reproduction
I followed the Capacitor Push guidelines explained here and added them to my project. I created a service that has the exact same code that appears in this guide, and use it when a user logs into my platform. The registration listener works well and shows me that alert with the token, which is good, but I can’t receive any pushes, both from my automated push server, or the Firebase Console. This is working exactly the same for both devices.
The same happens for a clean project, so it’s not a problem in my side. I am suspicious that something “might” be wrong in the Firebase side, but I tried making a completely new Firebase project for this purpose, which won’t work whatsoever.
Weird thing is that in the past I could get push notifications working from Cordova. They stopped working a couple of months ago, and after not being able to make this work with Cordova’s plugins (and having tons of problems with Cordova), I decided to switch to Capacitor, which felt much better and with more concise explanations. I still think it was a good move, but I still don’t understand why I am totally unable to make this work.
Things I tried:
- Use a clean app.
- Switch Firebase project and app, and therefore, use different google_services.json files.
- Absolutely all the Firebase/Firebase-x plugins in Cordova.
- Restart the Capacitor guide from 0, from a new project.
- Using another phone (mine is the Xiaomi, but it works the same for the Huawei I mentioned.
Other Technical Details
npm --version
output:
6.14.4
Additional Context
It’s been a long time since I first tried to fix this weird day-to-day push failure, and this is starting to become a serious professional problem to me. I really have to finish the app I’m working with, and the main requisite is that push notifications work on it. This may not be a Capacitor problem itself, but at this moment, I think I have isolated every possible problem that I could make in the process (either with my codebase or my tools), and this keeps doing the same: not working whatsoever.
So this is indeed a desperate call for help. I’ll even consider paying you guys if you struggle finding the problem and fixing it, and will provide access to my repo if someone needs it (although, as I mentioned, it doesn’t seem to have much to do with the project itself).
Thank you a lot for getting this far. Let’s see if we’re able to get this fixed!
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (1 by maintainers)
Top GitHub Comments
Hello everyone, I fix my problem reading the firebase repo and please feel free to try if this can solve your problems with push notifications:
here is the source https://github.com/firebase/firebase-android-sdk/issues/1339
In my case the notification never arrived because the app crashes on background when I recive the message. this was a problem inside firebase-messaging:20.1.2 and is solved in 20.1.4
I did this to fix the problem:
change the version located in android/variables.gradle from 20.1.2 to 20.1.4
Then in android studio go to “Files / Sync Project with Gradle Files”, remove your app from your device, compile again and works very well on background.
I think the default version of firebase messaging will be updated on the next versions of capacitor, but that works for me.
This is only my case, please feel free to try and thank you for your comments.
Strange. Not for me… When the app is closed or in the background I don’t receive any notifications. The notification received events in javascript work however (when the app is open)…