1 Reply Latest reply on Jun 28, 2017 10:07 AM by ryanskihead

    push.on('registration', no reaction on Android

    christianb79310854

      Hello.

       

      I use phonegap build to generate my app. I used the plugin one year, but now it doesnt work anymore..
      My App ID is 1046875

       

      Here is my config.xml Part:

       

      ```

      <preference name="phonegap-version" value="cli-6.5.0" />

       

      <plugin name="phonegap-plugin-push" source="npm">

                  <param name="SENDER_ID" value="xxx" />

              </plugin>

       

       

              <plugin name="cordova-plugin-calendar" />

              <plugin name="cordova-plugin-file" />

              <plugin name="cordova-plugin-file-transfer" />

              <plugin name="cordova-plugin-file-opener2" />

              <plugin name="cordova-plugin-inappbrowser" />

              <plugin name="cordova-plugin-network-information" />

              <plugin name="cordova-plugin-statusbar" />

              <plugin name="cordova-plugin-device" />

              <plugin name="cordova-plugin-whitelist" />

      ```

       

       

      My Sender ID from Google is correct and I use every plugin in the newest version.

      There is my complete init code, which works without any errors (test alerts are working good).

       

      ```

      var init = {

          initialize: function() {

              console.log('init.initialize');

       

              if (document.location.protocol == "file:") {

                  // file protocol indicates phonegap

                  document.addEventListener("deviceready", init.onDeviceReady, false);

              } else {

                  // browser on localhost, no phonegap

                  init.onDomReady();

              }

          },

         

          onDeviceReady: function() {

             

              $.support.cors = true;

             

              console.log('init.onDeviceReady ❤ running on DEVICE');

              init.run();

       

              document.addEventListener("online", onOnline, false);

              document.addEventListener("offline", onOffline, false);

             

             

              var push = PushNotification.init({

                  android: {

                      senderID: "xxx"

                  },

                  ios: {

                      alert: "true",

                      badge: true,

                      sound: 'true'

                  },

                  windows: {}

              });

             

              push.on('registration', function(data) {

                  final_token = data.registrationId;

                  window.localStorage.setItem("token", final_token);

                  alert(final_token); <!-- THIS ERROR DOESNT HAPPEN

                  var os = 1;

                  if(final_token.length == 64) {

                      os = 1;

                      //Apple

                  } else {

                      os = 2;

                      //Android

                  }

                 

                  $.ajax({

                      type: 'GET',

                      url: 'xxxxxx/api.php?rquest=set_device',

                      data:  { os: os, token: final_token },

                      crossDomain: true,

                      cache: false,

                      success: function(response) {

                         

                      }

                  });

              });

             

              push.on('notification', function(data) {               

                  alert(data.title + ': ' + data.message);

              });

       

       

              window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFail); 

       

       

          },

          onDomReady: function() {

              console.log('init.onDomReady ❤ running on DESKTOP');

              init.run();

          },

          run: function() {

              console.log('init.run');

          }

      };

      init.initialize();

      ```

       

      Does anyone have a clue or maybe a way to debug?

      Is it possible, that any other plugin crashed?

       

      I red more then 20 topics and nothing helped..

       

      Thanks a lot!