ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.31k stars 206 forks source link

No Toast message appearing #129

Closed dalefrancis88 closed 9 years ago

dalefrancis88 commented 9 years ago

Hey,

I think i have a user error isuse, when I use your package it runs well when i have the application open and i recieve the notification and everything is fine. However when the application is not active and i send the notification, nothing shows up on my android device. I know the messaging is working because if i open the app and cause the message a second time i see it being recieved. Any quick thoughts?

The below is the code i am using to send the message....

                    var message = new gcm.Message({
                        collapseKey: 'demo',
                        delayWhileIdle: false,
                        timeToLive: 3,
                        data: {
                            taskId: task._id, 
                            type: "Task Update"
                        }
                    });

                    // Set up the sender with you API key
                    var sender = new gcm.Sender('xxxxxx');

                    var registrationIds = [current.deviceId];

                    sender.send(message, registrationIds, function (err, result) {
                        if (err) console.error(err);
                        else console.log(JSON.stringify(result));
                    });
hypesystem commented 9 years ago

This is not an issue with the server. This is an issue with you not waking up the device when receiving notifications.

You used to have to use a WakefulBroadcastReceiver, but I think Google just made it even easier with Android M. Read their official guide: https://developers.google.com/cloud-messaging/android/client