I have to develop a frontend app with Ionic and a backend server with Java and Spring. I'm able to send and show notification via the Firebase console. The next step is to send notification via a Java server. This is the part of code that I'm using to send notification via the backend developed in Java:
Notification.Builder builder = Notification.builder();
MulticastMessage notMess = MulticastMessage.builder()
.setNotification(builder.build())
.putData("title", "Qualcuno รจ interessato al tuo post")
.putData("body", name+ ' '+ surname)
.addToken(user.getToken())
.build();
System.out.println("Sending notification...");
BatchResponse response = FirebaseMessaging.getInstance().sendMulticast(notMess);
System.out.println(response.getSuccessCount()+ " messages were sent successfully");
And it seems to work because the second sout prints "1 messages were sent successfully" but it isn't caught by the device where the client app is installed. Here's the code used in frontend app developed with Ionic:
import {Component, OnInit} from '@angular/core';
import { FirebaseX } from '@awesome-cordova-plugins/firebase-x/ngx';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent implements OnInit{
constructor(private firebaseX: FirebaseX) { }
ngOnInit(): void {
this.firebaseX.onMessageReceived()
.subscribe(data => console.log(`User opened a notification ${data}`));
}
}
Edit: I use
ionic Cordova run android --livereload
to execute the app, could it be the problem? If I try without live reload I get the error ERR_SOCKET_NOT_CONNECTED when the app is started, any idea about this?