question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Push plugin seems to work, but push notifications never arrive to any Android device

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
ivancdurancommented, Jul 10, 2020

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

ext {
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    androidxAppCompatVersion = '1.1.0'
    androidxCoreVersion =  '1.2.0'
    androidxMaterialVersion =  '1.1.0-rc02'
    androidxBrowserVersion =  '1.2.0'
    androidxLocalbroadcastmanagerVersion =  '1.0.0'
    firebaseMessagingVersion =  '20.1.4'
    playServicesLocationVersion =  '17.0.0'
    junitVersion =  '4.12'
    androidxJunitVersion =  '1.1.1'
    androidxEspressoCoreVersion =  '3.2.0'
    cordovaAndroidVersion =  '7.0.0'
}

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.

2reactions
rubenstolkcommented, Sep 7, 2020

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)…

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Pushwoosh Plugin] Sending push notifications success BUT ...
I'm trying to implement push notifications into my application, but I'm encountering ... is visible in pushwoosh dashboard , but never arrives on...
Read more >
Notifications Not Shown - Mobile Push
The following are reasons why notifications may show as "Delivered" on the OneSignal dashboard or API, but are not visible on your device....
Read more >
Android PushNotifications with PushPlugin on emulator
The fix is a lot simpler than it seems. I changed from: $scope.$on('$cordovaPush:notificationReceived', function (event, notification) {. to: $scope.
Read more >
Receive messages in an Android app - Firebase - Google
Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device's system tray. ·...
Read more >
Push Notifications Capacitor Plugin API
If no icon is specified Android will use the application icon, but push icon ... value) - sound : the device will ring/vibrate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found