Lev Lev - 1 year ago 337
Android Question

PUSH: Unable to get GCM project number, run "ionic config set gcm_key your-gcm-id"

I cannot send push notifications to android.
I updated to latest ionic cli
I updated to latest ionic lib
After that also did:

ionic config build


ionic prepare android

my io-config.json has


I've made
ionic config set gcm_key your-gcm-id
several time and replaced 'your-gcm-id' with my project ID.

but I still get this message:

PUSH: Unable to get GCM project number, run "ionic config set gcm_key your-gcm-id"

And when I try to register for ionic notification I also get:

$ionicPush:REGISTER_ERROR org.json.JSONObject$1 cannot be cast to java.lang.String

Lev Lev
Answer Source

So basically the problem is that Ionic framework had some changes :)

First of all some of the libraries like ionic-push and core were depricated and instead 'ionic-platform-web-client' should be used that replaces all the others.

In order to be able to install it you should update your ionic cli to the latest version.

(Don't forget to remove links to ionic core and ionic push from your index.html)

Also the registration code itself changed and you no longer waiting for event instead you should use the following code:

$ionicPlatform.ready(function() {

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

    push.register(function(token) {
      console.log("Device token:",token.token);

Several additional points for people who might get issues:

  1. Make sure you include PushNotification.js right after cordova.js

  2. if you cant install push notification plugin with

    ionic plugin add phonegap-plugin-push

try installing it with

cordova plugin add https://github.com/phonegap/phonegap-plugin-push
  1. after removing plugins especially ionic core - make sure to run

    ionic config build

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download