2

I'm using PhoneGap plugin to send out push notifications to Android app. Its working just fine. But the problem is that when the app is open the notifications are not being received but if I close the app then the notifications are coming in.

What could be the reason. I'd like to have the push notifications delivered in the system tray even when the app is running.

Jay Mayu
  • 17,023
  • 32
  • 114
  • 148

1 Answers1

0

This is by design and follows the normal UI conventions.

Luckily the plugin is open source, and you can change the behaviour.


Incoming push messages get processed by the GCMIntentService.

The onMessage() method checks if the app is in the foreground or not:

if (PushPlugin.isInForeground()) {
    extras.putBoolean("foreground", true);
    PushPlugin.sendExtras(extras);
}
else {
    extras.putBoolean("foreground", false);

    // Send a notification if there is a message
    if (extras.getString("message") != null && extras.getString("message").length() != 0) {
        createNotification(context, extras);
    }
}

Modify the if (PushPlugin.isInForeground()) {...} statement to accomplish what you need.


Another way would be to modify the code in PushPlugin.isInForeground() itself.

public static boolean isInForeground()
{
  return gForeground;
}

However be aware of any unwanted side-effects of changing this code. There may be other functionality that depends on this method (now and in the future).


See related post for a good explanation of how Parse push messages are received:

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255