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:
- Add HMS Core SDK dependencies and configure agconnect-services.json
- Create your custom HmsMessageService class
- Override onNewToken and call onTokenRefresh
- Override onMessageReceived and call onMessageReceived
- 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);
}
}
}
Content copied to clipboard
<service
android:name=".MyHmsMessageService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
Content copied to clipboard
See also
Types
Link copied to clipboard
AsyncTask for retrieving Huawei Mobile Services push token asynchronously.
Link copied to clipboard
interface OnGetTokenAsync
Callback interface for asynchronous HMS token retrieval.