Why is everything harder on Android? Push notification

Hello, I have a problem with Android (as always … in ANDROID), following I did an application using the ionic push system, with firebase. I’ll show you
IOS:

  1. I generated the GoogleService-Info.plis file and put it in my project
    2.configured my xml
<platform name = "ios">
<resource-file src = "GoogleService-Info.plist" />
</ platform>

3.Created apple certificate.
4. Tested and ran completely.
5.all ok…

NOW ON ANDROID

  1. I generated the file google-services.json

2.configured the xml

 <platform name = "android">
<resource-file src = "google-services.json" target = "application / google-services.json" />
</ platform>

3.configured xml with sender_id

   <plugin name = "phonegap-plugin-push" spec = "^ 2.1.3">
         <variable name = "FCM_VERSION" value = "11.6.2" />
        <variable name = "SENDER_ID" value = "42116867643" />
     </ plugin>

4. I gave the build and it just does not happen, it does not enter the metedos, I verify if it has permission it does not return anything at all …

My codes
it does not enter this hasPermission () method, only in IOS…

   this.push.hasPermission()
    .then((res: any) => {
      if (res.isEnabled) {
      alert("true");
      } else {
   alert("false")l
        this.navCtrl.setRoot(NotificationPage);
        this.updateDatas();
      }

    });
```

```
  setTokenPush(){
    const options: PushOptions = {
      android: {
        senderID: '42116867643'
      },
      ios: {
        alert: 'true',
        badge: true,
        sound: 'true'
      },
      windows: {},
      browser: {
        pushServiceURL: 'http://push.api.phonegap.com/v1/push'
      }
    };

    const pushObject: PushObject = this.push.init(options);
    pushObject.on('notification').subscribe((notification: any) => {
      let ethereumStr: string = notification.additionalData.data; // get the string
      let data: { datas: string } = JSON.parse(ethereumStr);
      this.response = data;
      this.data_ethereum =  this.response.datas.ethereum;
      this.data_bitcoin =  this.response.datas.bitcoin;
      this.data_litecoin =  this.response.datas.litecoin;
      this.storage.set('data_ethereum', this.data_ethereum);
      this.storage.set('data_litecoin', this.data_litecoin );
      this.storage.set('data_bitcoin', this.data_bitcoin); 
      this.navCtrl.push(LoadingPage,{  
        "message_loading":notification.title,
        "type":"receive",
      });
      

    });
    pushObject.on('registration').subscribe((registration: any) => {

      this.configPushUser(registration.registrationId);

    });

    pushObject.on('error').subscribe(error => {
    });

  }
  configPushUser(token){
    this.webservice.configPushUser(token).subscribe(data=>{

    });

  }
```

Define the resource file as:

<resource-file src="google-services.json" target="app/google-services.json" />

Make sure that you have the google-services.json file in the root of your project (in my case it’s not in the root, so I specified the full path is src, but in the example above I assumed it being in the root of the project, based on what you posted).

Then build:

ionic cordova build android

After the build, verify if the file was copied to [your-project]/platforms/android/app/google-services.json.

I’m assuming you are using cordova-android v7+

Yes it creates this file …

Put a console log in the registration, run your app in android and see in the logs if the registration is received successfully:

pushObject.on('registration').subscribe((registration: any) => {
    console.log('registration', registration);
    this.configPushUser(registration.registrationId);
});

Also it’s not clear to me if the code reachs the hasPermission call. If you put the logs:

console.log('hasPermission - before');

this.push.hasPermission().then((res: any) => {
    console.log('hasPermission - after', res);
    ...
}).catch(error => {
    console.log('hasPermission - error ', error );
    throw error;
});

do you receive only the first log? Or the one with after or error is called too? That may help to diagnose the problem.

1 Like

Hello, there is no error in it (CLASS NOT FOUND)