0

I am using the node-gcm module to send Push Notifications to my Cordova app.
The server reports that it has successfully delivered the message to my device.

The notifications appear on the device if the app is running in the background, but do not come up if the app is not running at all.

From my reading I believe I need to set priority: 'high' to fix this, however from my tests this does not work. Either I am setting that incorrectly, or there is something else I need to do.

Here is my send code:

var msgJson = {
                priority: 'high',
                contentAvailable: true,
                "data": {
                    title: title,
                    body: message_text,
                    icon: 'ic_launcher',
                    sound: true,
                    extra_data
                }
};


var message = new gcm.Message( msgJson );

console.log(message);

sender.send(message, { registrationTokens: push_tokens }, function (err, response) {

    if(err) {
        console.error('Error sending Google Cloud Message notification:', err, response);
    } else {
        console.log('Android notification successful send to', push_tokens, response);
    }

});

Why are my notifications not coming up on the device when the app is fully closed?

kris
  • 11,868
  • 9
  • 88
  • 110

1 Answers1

0

It is stated in this thread that force stopping an application by the user puts the application in a stopped state and none of its code is run, including any broadcast receivers declared in manifest. Only when the user explicitly launches the app it is put in a state where the receivers get fired.

You can also read in this documentation that the value of delay_while_idle must be set to true. If the device is connected but idle, the message will still be delivered right away unless the delay_while_idle flag is set to true.

Here's a related thread which might help:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • I did do a fair bit of research myself before posting an answer and I had come across that same information that broadcasts don't arrive if the app is fully closed - but I just can't believe it, some apps (like gmail) do manage it. I also tried the delay_while_idle flag, but I believe that is for a network connectivity thing and so I left it out of my answer that I had tried that. I appreciate your research and your leaving an answer -- I'm really hoping to get an answer from someone who has actually faced and solved the same problem. – kris Nov 09 '16 at 04:40
  • I have come across something that I think is likely the way to go, and I will try it next, but it requires modifying my client code so I'd put it off until last : http://stackoverflow.com/a/24314088/1290746 (http://stackoverflow.com/questions/24313539/push-notifications-when-app-is-closed) Again - thank you for your answer and I hope my reply didn't sound ungrateful - I've spent a long time on this with little luck and no success and I am feeling very tired and sad. – kris Nov 09 '16 at 04:43