ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
509 stars 577 forks source link

Dont receive Push notifications when app is killed (@capacitor/push-notifications) #1019

Open hanslbua opened 2 years ago

hanslbua commented 2 years ago

Bug Report

Plugin(s)

@capacitor/push-notifications

Capacitor Version

Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 3.5.1
@capacitor/core: 3.5.1
@capacitor/android: 3.5.1 @capacitor/ios: 3.5.1

Installed Dependencies:

@capacitor/cli: 3.4.3 @capacitor/android: 3.4.3 @capacitor/core: 3.4.3 @capacitor/ios: 3.3.3

[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

hello. i have a question. is use @capacitor/push-notifications for push notifications. on ios everything works as expected, but on android i get only notifications, when the app is in foreground. when the app is in background or killed i dont get any push notification from firebase. firebase seems to be right configured, because it works in foreground + on ios.

i read this on npm site: This plugin does support data-only notifications, but will NOT call pushNotificationReceived if the app has been killed. To handle this scenario, you will need to create a service that extends FirebaseMessagingService, see Handling FCM Messages.

can someone help me, getting push notification also when my app is in background or killed?

indraraj26 commented 2 years ago

I am having similar issue and not able to understand what to extend in order to support background notification so that It can trigger pushNotificationReceived

https://github.com/ionic-team/capacitor-plugins/issues/964#issuecomment-1125290371

gldstrrbt commented 2 years ago

Having the same issue, but with localNotifications and background tasks

crowbait commented 1 year ago

This may be a bit late, but you can extend the FirebaseMessagingService on Android pretty easily. This is a good starting point. The main idea is:

As far as I know, that should about do it. Problem is, that service extension doesn't seem to work while the Cap push plugin is listening to the same event; at least I can't get it working. Have a look here: https://github.com/ionic-team/capacitor-plugins/issues/1211 The code examples I've posted in the original issue should help you get started.

crowbait commented 1 year ago

Heads up: the issue I was talking about is non-existent. There was an oversight in the Firebase documentation, which has been rectified. You're good to go.

alexthunder3 commented 4 weeks ago

Is there a working solution posted anywhere?

crowbait commented 4 weeks ago

Is there a working solution posted anywhere?

See my comment above. I could pull it off without ever having used Java before, so you'll probably be just fine.