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:

  1. Create your custom FirebaseMessagingService class
  2. Override onNewToken and call onTokenRefresh
  3. Override onMessageReceived and call onMessageReceived
  4. 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);
        }
    }
}
AndroidManifest.xml:

<service
    android:name=".MyFirebaseMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

See also

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open fun isPushwooshMessage(remoteMessage: RemoteMessage): Boolean
Checks whether a Firebase Cloud Messaging message was sent through Pushwoosh.
Link copied to clipboard
open fun messageToBundle(remoteMessage: RemoteMessage): Bundle
Converts a Firebase Cloud Messaging RemoteMessage to an Android Bundle.
Link copied to clipboard
open fun onMessageReceived(context: Context, remoteMessage: RemoteMessage): Boolean
Processes incoming Firebase Cloud Messaging push notifications for Pushwoosh.
Link copied to clipboard
open fun onTokenRefresh(token: String)
Notifies Pushwoosh when Firebase Cloud Messaging token is refreshed.