Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

[Android 5.1] Case study: depending on notif payload, onNotification callback not called when notif clicked while app in background #746

Open
jakub-g opened this issue Mar 23, 2016 · 5 comments

Comments

@jakub-g
Copy link
Contributor

jakub-g commented Mar 23, 2016

Expected Behaviour

The onNotification callback should be fired when user clicks the notif in notification drawer, regardless if the app was not in foreground / background / not running

Actual Behaviour

When the app is in background when user clicks the notif, or the app was started from user clicking the notification, the callback may not get called, depending on the notif payload

Reproduce Scenario (including but not limited to)

  1. Launch the app on Android and make it go to background
  2. Send a notification with node-gcm
  3. Observe the notification is displayed in the notification drawer.
  4. Click the notification
  5. Check the logs in Chrome Dev Tools

Platform and Version

Android 5.1

(Android) What device vendor

Motorola MotoG3

Cordova CLI version and cordova platform version

cordova --version
> 6.0.0
cordova platform version android
> 4.1.1

Plugin version

cordova plugin version | grep phonegap-plugin-push
> 1.6.0

Sample Code that illustrates the problem

_pushPlugin = window.PushNotification.init({
  android: {
    senderID: GCM_SENDER_ID,
    iconColor: "blue",
    icon: "push_notification_icon",
    // when app is in foreground, we want the callback called immediately, without displaying
    // the notif in notification drawer
    forceShow: false
  }
});

_pushPlugin.on('error', function(err) {
  $log.error('[onError]');
});

_pushPlugin.on('registration', function(data) {
  $log.info('[onRegistration]');
}

_pushPlugin.on('notification', function(data) {
  $log.info('[onNotification]');
}

Sample Push Data Payload

Will post separate cases in the next message

@jakub-g
Copy link
Contributor Author

jakub-g commented Mar 23, 2016

Actual behavior

So depending on the payload in node-gcm, the plugin behaves differently.

Sometimes, the phonegap-plugin-push#onNotification is called just fine, but sometimes it is not called.

Accidentally, since I'm also using a webintent plugin, registered as window.plugins.webintent.onNewIntent(__myHandleWebIntentCb);, I've noticed in the cases where phonegap-plugin-push#onNotification is not called, the webintent's callback is called instead, which may shed some light on the underlying issue.

Though I think, the presence of webintent plugin is not the reason of the bug. When I remove the webintent plugin from the app, no callback is still called,

So here are the different cases:

1a) [onNotification] is called

var message = new gcm.Message();
message.addData({
    customField: 'my custom field',
    alert: 'ALERT'
});

1b) [onNotification] is called

var message = new gcm.Message({
    notification: {}
});
message.addData({
    customField: 'my custom field',
    alert: 'ALERT'
});
  1. [onNotification] NOT CALLED, instead __myHandleWebIntentCb is called!
var message = new gcm.Message({
    notification: {
        icon: 'push_notification_icon',
        color: 'blue'  
    }
});
message.addData({
    customField: 'my custom field',
    alert: 'ALERT'
});
  1. [onNotification] NOT CALLED, instead __myHandleWebIntentCb is called!
var message = new gcm.Message({
    notification: {
        title: "TITLE",
        body: "BODY"
    }
});
message.addData({
    customField: 'my custom field',
    alert: 'ALERT'
});

And here's how different cases look in the UI:

notifs_depending_on_gcm_payload

@jakub-g
Copy link
Contributor Author

jakub-g commented Mar 23, 2016

I originally tested with 1.5.3 but the behavior is identical in 1.6.0

@jakub-g
Copy link
Contributor Author

jakub-g commented Mar 23, 2016

You can also see in one of the cases the icon is not displayed, I opened #747 for that

@jakub-g jakub-g changed the title Case study: depending on notif payload, onNotification callback not called when notif clicked while app in background [Android 5] Case study: depending on notif payload, onNotification callback not called when notif clicked while app in background Mar 23, 2016
@jakub-g jakub-g changed the title [Android 5] Case study: depending on notif payload, onNotification callback not called when notif clicked while app in background [Android 5.1] Case study: depending on notif payload, onNotification callback not called when notif clicked while app in background Mar 23, 2016
@macdonst
Copy link
Member

@jakub-g Yeah, the problem is when you add the notification property to the gcm.Message object with a title and body the OS takes over. Once the OS takes over the plugin never gets called. It's on my list to look into but for now I suggest not populating the notification object. That's why all of my sample node-gcm scripts use the data object only.

@VivaBem
Copy link

VivaBem commented Apr 7, 2016

Hello, i noticed when i avoid to set notification (as said before), the phone receives the push, but it comes empty (no title, no body, no sound) on the notification drawer. The title, body and sound are defined on the data object.

The strange behavior is that it works for the first message that arrives on the message bar (it comes with title, body and sound), but the others come empty.

Any idea how to solve it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants