PushwooshHmsHelper

Helper class for integrating Pushwoosh with Huawei Mobile Services (HMS) Push Kit in custom HmsMessageService implementations.

By default, Pushwoosh SDK automatically handles Huawei Mobile Services push notifications without any additional code. However, if your app needs a custom HmsMessageService (for example, to handle messages from multiple push providers), use this helper class to forward HMS callbacks to Pushwoosh.

Important: Use this helper ONLY if you need a custom HmsMessageService. For customizing notifications, use com.pushwoosh.notification.NotificationServiceExtension instead.

Critical Integration Steps:

  1. Add HMS Core SDK dependencies and configure agconnect-services.json
  2. Create your custom HmsMessageService class
  3. Override onNewToken and call onTokenRefresh
  4. Override onMessageReceived and call onMessageReceived
  5. Register your service in AndroidManifest.xml

Example - Multiple Push Providers:


public class MyHmsMessageService extends HmsMessageService {

    
    public void onNewToken(String token) {
        super.onNewToken(token);

        // CRITICAL: Forward to Pushwoosh to keep receiving notifications
        PushwooshHmsHelper.onTokenRefresh(token);

        // Forward to other providers if needed
        OtherProvider.setToken(token);
    }

    
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        // CRITICAL: Route Pushwoosh messages to Pushwoosh
        if (PushwooshHmsHelper.isPushwooshMessage(remoteMessage)) {
            PushwooshHmsHelper.onMessageReceived(this, remoteMessage);
        } else {
            // Handle other providers
            OtherProvider.handleMessage(remoteMessage);
        }
    }
}
AndroidManifest.xml:

<service
    android:name=".MyHmsMessageService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
    </intent-filter>
</service>

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
open class GetTokenAsync
AsyncTask for retrieving Huawei Mobile Services push token asynchronously.
Link copied to clipboard
interface OnGetTokenAsync
Callback interface for asynchronous HMS token retrieval.

Functions

Link copied to clipboard
open fun isPushwooshMessage(remoteMessage: RemoteMessage): Boolean
Checks whether a Huawei Mobile Services message was sent through Pushwoosh.
Link copied to clipboard
open fun onMessageReceived(context: Context, remoteMessage: RemoteMessage): Boolean
Processes incoming Huawei Mobile Services push notifications for Pushwoosh.
Link copied to clipboard
open fun onTokenRefresh(token: String)
Notifies Pushwoosh when Huawei Mobile Services push token is refreshed.