Getting push-plugin to work for android

Hi folks,
I have iOS push notifications working very well using GitHub - phonegap/phonegap-plugin-push: Register and receive push notifications
For Android, it compiles but when I run the app, push registration fails. I went to google developer console and generated a sender-ID.

their website talks about GCM support libraries et al - and just puts a link to the GCM site.

Can someone please explain succinctly what one needs to do to integrate this into ionic build android in a way that pulls in whatever libraries are needed?

For example they say:

As of version 1.3.0 the plugin has been switched to using Gradle/Maven for building. You will need to ensure that you have installed the Android Support Library version 23 or greater, Android Support Repository version 20 or greater, Google Play Services version 27 or greater and Google Repository version 22 or greater.

I have all those packages - but how do I tie them into my app?

thanks!

for android, this works for me with the phonegap-push-plugin

//es6
let deviceConfig = {
  "android": {
    "senderID": Constants.GOOGLE.GCMSENDERID
   },
   "ios": {
     "alert": true,
     "badge": true,
     "sound": true
   },
   "windows": {}
};
this.pushNotificationHandler = window.PushNotification.init(deviceConfig);
this.pushNotificationHandler.on("registration",(data) => {
  let registrationid = data.registrationId;
  //...
}

in the android-sdk-manager install from Extras: Android Support Repository, Android Support Library, Google Play services, Google Repository
think thats all?!

Hello @Bastian,
That’s very odd. Can you see if my setting matches yours:

a) The Android SDK manager shows them installed

b) My plugin list (please see if you have any other plugins related to push)

com.ionic.keyboard 1.0.4 "Keyboard" com.phonegap.plugins.OrientationLock 0.1 "OrientationLock" cordova-plugin-crosswalk-webview 1.3.1 "Crosswalk WebView Engine" cordova-plugin-file 2.1.0 "File" cordova-plugin-inappbrowser 1.0.0 "InAppBrowser" cordova-plugin-ios-longpress-fix 1.0.1 "iOS LongPress Fix" cordova-plugin-splashscreen 2.1.0 "Splashscreen" cordova-plugin-touchid 0.3.0 "Touch ID" cordova-plugin-websocket 0.11.0 "WebSocket for Android" cordova-plugin-whitelist 1.0.0 "Whitelist" de.appplant.cordova.common.registerusernotificationsettings 1.0.1 "RegisterUserNotificationSettings" de.appplant.cordova.plugin.badge 0.7.1 "Cordova Badge Plugin" de.appplant.cordova.plugin.email-composer 0.8.2 "EmailComposer" de.appplant.cordova.plugin.local-notification 0.8.2-dev "LocalNotification" hu.dpal.phonegap.plugins.PinDialog 0.1.3 "PinDialog" nl.x-services.plugins.insomnia 4.0.1 "Insomnia (prevent screen sleep)" org.apache.cordova.console 0.2.13 "Console" org.apache.cordova.device 0.3.0 "Device" org.apache.cordova.statusbar 0.1.10 "StatusBar" org.devgeeks.Canvas2ImagePlugin 0.6.0 "Canvas 2 Image" phonegap-plugin-push 1.3.0 "PushPlugin" uk.co.whiteoctober.cordova.appversion 0.1.7 "AppVersion"

c) My registration code:

``
var push = PushNotification.init(
{ “android”:
{“senderID”:“zmninja-96b55”}
},

                 { "ios": 
                 {"alert": "true", 
                  "badge": "true", 
                  "sound": "true"}
                }  
                 
            );

``

On android, this results in my error handler being called

push.on('error', function(e) {
                     console.log ("************* PUSH ERROR ******************");
                });
                    

Well, that was silly of me. I was using the project name, not the ID.
Working now!

@Bastian , did you make any changes to any manifest file? My app is getting the registration token, but in Android I am not getting any callback during notification

no, i didn’t

this.pushNotificationHandler.on("notification", (data) => {
  console.log(data);
});

the notification need to have a title or a message on the data-property, seen in the plugin-sourcecode
example push-server-code:

var gcmmessage = new gcm.Message({
  collapseKey: 'demo',
  priority: 'high',
  contentAvailable: true,
  delayWhileIdle: true,
  timeToLive: 3,
  restrictedPackageName: 'somePackageName',
  dryRun: false,
  data: {
    title: 'title on data',   // <- this
    message: 'message on data' // <- or this
  },
  notification: {
    title: 'Hello, World',
    icon: 'ic_launcher',
    body: 'This is a notification that will be displayed ASAP.',
  }
});

edit: cleaner

Perfect. Everything works! Thanks!