PushwooshFcmHelper
Helper class for integrating Pushwoosh with Firebase Cloud Messaging (FCM) in custom FirebaseMessagingService implementations.
By default, Pushwoosh SDK automatically handles Firebase Cloud Messaging without any additional code. However, if your app needs a custom FirebaseMessagingService (for example, to handle messages from multiple push providers), use this helper class to forward Firebase callbacks to Pushwoosh.
Important: Use this helper ONLY if you need a custom FirebaseMessagingService. For customizing notifications, use com.pushwoosh.notification.NotificationServiceExtension instead.
Critical Integration Steps:
- Create your custom FirebaseMessagingService class
- Override onNewToken and call onTokenRefresh
- Override onMessageReceived and call onMessageReceived
- Register your service in AndroidManifest.xml
Example - Multiple Push Providers:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public void onNewToken(@NonNull String token) {
super.onNewToken(token);
// CRITICAL: Forward to Pushwoosh to keep receiving notifications
PushwooshFcmHelper.onTokenRefresh(token);
// Forward to other providers if needed
OtherProvider.setToken(token);
}
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
// CRITICAL: Route Pushwoosh messages to Pushwoosh
if (PushwooshFcmHelper.isPushwooshMessage(remoteMessage)) {
PushwooshFcmHelper.onMessageReceived(this, remoteMessage);
} else {
// Handle other providers
OtherProvider.handleMessage(remoteMessage);
}
}
}
Content copied to clipboard
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Content copied to clipboard
See also
FirebaseMessagingService
Functions
Link copied to clipboard
Checks whether a Firebase Cloud Messaging message was sent through Pushwoosh.
Link copied to clipboard
Converts a Firebase Cloud Messaging RemoteMessage to an Android Bundle.
Link copied to clipboard
Processes incoming Firebase Cloud Messaging push notifications for Pushwoosh.
Link copied to clipboard
Notifies Pushwoosh when Firebase Cloud Messaging token is refreshed.