If your application uses Pushwoosh alongside another push provider or your own Firebase Cloud Messaging (FCM) implementation, you may see registration problems — devices showing up as "Unknown Platform", invalid push tokens, or Pushwoosh notifications simply not being displayed. This happens because only one FirebaseMessagingService in an app wins, and whichever one that is must forward events to every SDK that needs them.
The fix is a single, consolidated FirebaseMessagingService that routes tokens and messages to all the services in your app.
Step 1: Create a Custom Messaging Service
Create a class that extends com.google.firebase.messaging.FirebaseMessagingService.
import androidx.annotation.NonNull;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.pushwoosh.firebase.PushwooshFcmHelper;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
// ...
}
Step 2: Handle New Tokens
Override onNewToken() and forward the token to Pushwoosh with PushwooshFcmHelper.onTokenRefresh(token). Note the method takes the token only — no Context.
@Override
public void onNewToken(@NonNull String token) {
super.onNewToken(token);
// Forward the new FCM token to Pushwoosh
PushwooshFcmHelper.onTokenRefresh(token);
// TODO: register the token with your other push service here
// e.g., myOtherService.registerToken(token);
}
Without this call, Pushwoosh will not be able to send notifications to the device after a token refresh.
Step 3: Handle Incoming Messages
Override onMessageReceived(). Ask Pushwoosh whether the message is its own with PushwooshFcmHelper.isPushwooshMessage(); if it is, hand it to PushwooshFcmHelper.onMessageReceived() (which takes a Context and returns true when it handled the message). Otherwise pass the message to your other provider.
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
if (PushwooshFcmHelper.isPushwooshMessage(remoteMessage)) {
PushwooshFcmHelper.onMessageReceived(this, remoteMessage);
} else {
// TODO: handle the message with your other push service's logic
// e.g., myOtherService.handleMessage(remoteMessage);
}
}
Step 4: Update AndroidManifest.xml
Register your router service and make sure no other FirebaseMessagingService is declared, so the system cannot pick a different one.
<application ...>
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
See also: Using Pushwoosh SDK with other FCM services.
Comments
0 comments
Please sign in to leave a comment.