Luis Dalmolin Luis Dalmolin - 5 months ago 33
AngularJS Question

Ionic Push on Android: unexpected error occured

I'm trying to use Ionic Push notifications on android, but every time I got the following error:


Ionic Push:, (debug) unexpected error occured.
Ionic Push:, [object Object]


I'm using Genymotion as my emulator, with Google Play Services installed (https://stevenkideckel.wordpress.com/2014/12/27/how-to-install-google-play-services-on-genymotion/). Testing on a real device is not working as well.

Also, I'm using this push plugin (https://github.com/phonegap/phonegap-plugin-push), and installed like this:

ionic plugin add phonegap-plugin-push --variable SENDER_ID="my-gcm-project-number"


My push code look's like this:



var push = new Ionic.Push({
'debug': true,

'pluginConfig': {
'android': {
'senderID': 'my-project-number',
'iconColor': '#343434'
}
}
});

push.register(function(token) {
console.log('Device token:', token.token);
push.saveToken(token);
});





I already configured my Ionic app using:

ionic config set dev_push false
ionic push --google-api-key my-google-api-key
ionic config set gcm_key <my-gcm-project-number>


I tried to search for similar problemas but never found a solution.

Anyone can help me?
Thanks!

Answer

To answer my own question:

When I published my app and testing on a real Android device downloading the app from Google Play, it worked.

A few things to try if you are getting this problem:

Remove and add again the push plugin:

ionic plugin remove phonegap-plugin-push
ionic plugin add phonegap-plugin-push --variable SENDER_ID="my-gcm-project-number"

Also:

  • Generate a new project number and API key on Google Console;
  • Check .io-config.json to check if your keys and numbers are correct;
  • Make sure your dev push is off: ionic config set dev_push false;
  • Set your GCM key on Ionic IO: ionic config set gcm_key <your-gcm-project-number>;
  • Check (and make it again if needed) your build profiles on Ionic IO;

Also check this answer: https://forum.ionicframework.com/t/ionic-push-not-working-on-android/52636/2

Hope this help someone.

Comments