phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

`notification` event isn't received when launched by pressing a notification #2605

Closed jmeyers91 closed 5 years ago

jmeyers91 commented 5 years ago

Expected Behaviour

When I press a notification, my app should be launched and then either receive the notification event or there should be some mechanism to check the launch notification.

Actual Behaviour

No notification event is received and there doesn't appear to be any way to access the notification used to launch the app.

Reproduce Scenario (including but not limited to)

I run PushNotification.init then I ensure I have permissions with PushNotification.hasPermission then I listen for the registration token with pushNotifications.on('registration') then I send it to the server and listen for a notification event. The event is received if the app is in the foreground, but it isn't received if the app is launched from the notification from being terminated or in the background.

I've also tried adding the notification listener immediately after the deviceready event in-case I was missing it.

Steps to Reproduce

Send a notification to an Android phone while the listening app is in the background/terminated. Press the notification. Observe that no notification event was received by the app.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 8.0.0

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

LG G6

Cordova CLI version and cordova platform version

cordova --version                                    # e.g. 6.0.0
8.1.2 (cordova-lib@8.1.1)

cordova platform version android                     # e.g. 4.1.1
android 7.1.1

Plugin version

cordova plugin version | grep phonegap-plugin-push   # e.g. 1.5.3
phonegap-plugin-push 2.2.3 "PushPlugin"

Sample Push Data Payload

{foo: 'bar'}

The full code used to send test notifications (from Node using the firebase-admin module)

firebase.messaging().send({
  data: {foo: 'bar'},
  notification: {
    title: 'This is a notification title',
    body: 'This is a notification body',
  },
  token: deviceRegistrationId,
});
MnGuii commented 5 years ago

I have the same problem. That is my payload sent to https://fcm.googleapis.com/fcm/send:

{
    "to" : "registrationId",
    "notification" : {
        "body": "Hello"
    },
    "data" : {
            "custom_data" : "test"
    }
}

I'm using the same cordova, android and plugin version that @jmeyers91

fredgalvao commented 5 years ago

Please (re)read this section of the docs and see if it explains well enough why you shouldn't send both notification and data root attributes on the payload: https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#notification-vs-data-payloads

If it doesn't, please help us improve the docs.

Also, if this is not the root of the problem (and using data-only payload doesn't solve it), feel free to re-open the issue.

lock[bot] commented 5 years ago

This thread has been automatically locked.