capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

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

Open hanslbua opened this issue 3 years ago • 6 comments

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?

hanslbua avatar Jun 01 '22 20:06 hanslbua

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

indraraj26 avatar Jun 02 '22 15:06 indraraj26

Having the same issue, but with localNotifications and background tasks

gldstrrbt avatar Aug 19 '22 22:08 gldstrrbt

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:

  • create a new Java file with a class that literally extends FirebaseMessagingService
  • listen to onMessageRecieved in that service
  • register the service in the app manifest

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 avatar Oct 05 '22 16:10 crowbait

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.

crowbait avatar Oct 05 '22 20:10 crowbait