Push Notification - register with android

Hi ,

I’m trying to register my android app with the GCM.
The register function works well, so it seems everything else is ok and the GCM is well connected.

To get the reg id I need to listen for the $cordovaPush:pushNotificationReceived event, but it seems that the event doesn’t fire at all.

Is there anyone who might have an idea why it does not work?

Thank you

When I started working with GCM I followed this tutorial.

Maybe this helps. It’s quit hard to help you debugging code without further details/code.

First you should activate GCM service for your project in your google dev console.
After that you can register a device and the device will get the notification.

Are you using some services, that sends the notifications for your?

I implemented APN and GCM with nodejs for my apps.
In that cases you need to connect with your apiKey to gcm service and send it to your device.

Does your device gets the notification or does simply your “In-App”-Handling of the notification is not working.

greets bengtler.

thx for your answers.

I’ll try to explain more, I activate the GCM service and in my app I’ve been able to register to this service with the App ID.
But in android to get the Register Id you have to get it from the $cordovaPush:pushNotificationReceived event before I would able to keep sending messages.

@Jansen I tried this tutorial, it helps me a lot but he is a little bit out of date.

this is my register function:

  $cordovaPush.register(config).then(function (result) {
          console.log("Register success " + result);
    
          if (ionic.Platform.isIOS()) {
                        // code for ios ...
            }
   }, function (error) {
       console.log("Register error " + error);
  });

here is my notification received listener:

$rootScope.$on('$cordovaPush:pushNotificationReceived', function (event, notification) {
     console.log('push Notification Received');

     if (ionic.Platform.isAndroid()) {
          // code for android ...
     }
});

the console.log('push Notification Received'); didn’t occur at all

maybe try it outside of angular first, like they do on github. After this start migrating your code to angularjs.

// Edit: Could you post the config variable too?

I don’t really understand why you use $on instead of just coding a normal method within $cordovaPush.

1 Like

I use it because this is what I read from the ng-cordova docs: http://ngcordova.com/docs/plugins/pushNotifications/

the config is just the project number from GCM: config = { "senderID" : projNumber };

And you added your listener in your run-Block?
Maybe your is not executed?

I don’t understand what you mean.the listener is in my controller, the register function also in this controller and it works.

I was debugging the cordova code and it seems it doesn’t get to the onNotification function, that from there the broadcast sent,
maybe I didn’t do something in the GCM?

Strange, I personally would try the code from github. On this way you can check if it’s a code or a GCM problem.

I’m having the same issue as @brikmando, If anyone has any thoughts regarding this, it would really help. Thanks!

Also, did you find a solution to the issue, @brikmando?