Ionic Push: GCM project number not found in android application

1.2k Views Asked by At

I'm trying to use ionic.io to send push notification. Here is what I did :

  1. Create an app in GCM and enable GCM API.

enter image description here

  1. Create credentials and get the api key.

enter image description here

  1. Create an app in ionic.io dashboard
  2. Create a security profile and add the api key

enter image description here

  1. Create an api token in ionic.io dashboard

enter image description here

  1. My source code in app.js which generated by ionic start pushdemo

    .run(function($ionicPlatform) {
    
    $ionicPlatform.ready(function() {
    
    var push = new Ionic.Push({
      "debug": true
    });
    
    push.register(function(token) {
      alert(token.token);
      console.log("Device token:",token.token);
      push.saveToken(token);
    });
    

7.Add push plugin:

ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"

I tried both with or without quotation mark around myproject_number. It's the project number in step 1.

8.Set the dev_push to false

9.Hook my app to ionic.io by ionic io init

10.Run ionic run android -lc

Found the following error message:

enter image description here

What's wrong with it? Can anybody help? Thanks.

3

There are 3 best solutions below

6
On

i had the same problem its generally because of proxy issue you are behind the proxy it means you are using internet by making request to the server ,so first you should use your own internet (in this case if you use WIFI then also it will work ) second aafter creating your project dirsctly make login from your cinsole to ionic io it will ake for email and password that will make your app live third

ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"

use quotes for entering your project number.project number also called GCM number and your server key is the key you generated in same project means google console which enable you to use google services. and dont forget to add android platform

1
On

add this code in your app.js

.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
     var push = new Ionic.Push({
      "debug": true
        });

       push.register(function(token) {
      console.log("My Device token:",token.token);
      push.saveToken(token);  // persist the token in the Ionic Platform
        });
    });
    })

and dont forget to run below command

ionic config set dev_push true

when you are testing it on browser make above cammand true,this means developmant mode ,and when you are making apk this time you have to make above command false

1
On

ionic start pushCall ionic login ionic upload

//open google console 1-create project 2-use google api 1-mobile APIs 2-select google cloud messaging and eneble it 3- go to credential and create API key

//after that add following plugin

ionic add ionic-platform-web-client ionic plugin add phonegap-plugin-push --variable SENDER_ID="991785317333" (dont remove quotes while adding gcm number)

//add platfom

ionic platform add android ionic io init ionic config set dev_push true

//open ionic io go to setting 1-create api key
2-go to certificate and create security profile name edit id click on android and add GCM key and save it.

//add this code to app.js


angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
 var push = new Ionic.Push({
  "debug": true
    });

   push.register(function(token) {
  console.log("My Device token:",token.token);
  push.saveToken(token);  // persist the token in the Ionic Platform
    });
});
})

//to test wether your configure correctly with ionic io open launch postman //and then do the following things:

1-create collection give it a valid name
2-in body click on text and select Application/json
it will add header automatically
3-add another header     
key as Authorization
value as bearer followed by your api token from ionic io
4-select "raw " as the format of our json
2-in body section of your collection write
following code
{
"tokens": ["DEV_DEVICE_TOKEN"],
    "profile": "PROFILE_NAME",
    "notification":
     {
    "message": "This is my demo push!"
     }
}

//now it will prompt message on browser

ionic config set gcm_key
ionic config set dev_push false ionic build android

install your app in mobile and send the notification from postman

(Mahesh Sampat Nighut) navi mumbai