ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.71k stars 990 forks source link

Android Push only works with active app #2902

Closed Sebxx closed 4 years ago

Sebxx commented 4 years ago

Bug Report

Capacitor Version

npx cap doctor output:

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 2.1.0

  @capacitor/core: 2.1.0

  @capacitor/android: 2.1.0

  @capacitor/electron: 2.1.0

  @capacitor/ios: 2.1.0

Installed Dependencies:

  @capacitor/electron not installed

  @capacitor/cli 2.0.1

  @capacitor/core 2.0.1

  @capacitor/android 2.0.1

  @capacitor/ios 2.0.1

[success] Android looking great! 👌
  Found 4 Capacitor plugins for ios:
    @rdlabo/capacitor-facebook-login (2.0.2)
    cordova-plugin-googleplus (8.4.0)
    cordova-plugin-market (1.2.0)
    cordova-plugin-sign-in-with-apple (0.1.1)
[success] iOS looking great! 👌

Affected Platform(s)

Current Behavior

I am using the Capacitor's PushNotification plugin to register tokens and listen the notifications. The FCM and APNS tokens are registered directly to AWS SNS service. I'm sending custom and general notifications using the Node AWS SDK. In iOS I can get both the notification when the app is opened (in which I perform an alert) and when the app is killed (OS notifications tray). But in Android I can only get the notification when the app is opened. I can't get the pushNotificationActionPerformed event when the app is inactive or killed because the notification is not being shown in the notifications tray.

Expected Behavior

Get the notification by the OS in the notifications tray in Android as I can get the payload when the application is in opened status.

Sample Code or Sample Application Repo

Reproduction Steps

Send an automatically notification when an administrative user performs an action. Then, the notification is shown only if the user has opened the application.

Other Technical Details

npm --version output: 6.14.5

node --version output: v12.14.0

pod --version output (iOS issues only):

Other Information

jcesarmobile commented 4 years ago

On Android there are two types of notification payloads, data and notification.

If you use notification payload the notification is displayed when the app is in the background and if the app is fully closed, that's handled by the OS, not by Capacitor, then when you tap it pushNotificationActionPerformed is called. If the app is in foreground then pushNotificationReceived is called.

If you use data payload, the notification is not displayed on any app state, pushNotificationReceived is called on background and foreground, but not when fully closed (used to work, but it's broken now, known and reported issue), pushNotificationActionPerformed is never called.

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.