I have this class that implement a service :
public class myFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
}
}
now from another class (another service in fact) I would like to call onMessageReceived(RemoteMessage remoteMessage) but I don't know how to do this.. Is it possible ?
I had a similar problem. I had two services using the same intent filters. To solve the problem, I decided to create a third service, which was subscribed to the intent filters. Inside this service, I instantiated each service and just passed the received message to them. The problems if you just instantiate the services are related to the Context because you haven't it.
Checking all methods inside the services I saw that you have a protected method attachBaseContext(context); so I created a public method to set the base context from my wrapper services, something like this:
public class WrapperService extends FirebaseMessagingService {
public void onMessageReceived(RemoteMessage message) {
Service1 service1 = new Service1(getBaseContext());
service1.onMessageReceived(message);
Service2 = new Service2(getBaseContext());
service2.onMessageReceived(message);
}
}
Now, for each service I have something like this:
public class Service1 extends FirebaseMessagingService {
public Service1(Context context) {
super.attachBaseContext(context);
}
public void onMessageReceived(RemoteMessage message) {
....
}
}
With these changes, I was able to call both services using the same intent filters.
As a final thought, If you don't have access to the services itself because they are included in a third party library you should check the possibility to extend a class from that service and add a public constructor to that class in order to initialize the Base Context.
There is no point of doing that, basically you would be sending a notification to yourself.
If that is your purpose, just create the notification where you wanna call onMessageReceived();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With