Skip to content

How can I achieve handling by Infobip's Huawei and my Huawei messaging service?

Konstantin edited this page Jul 29, 2020 · 1 revision

Let's assume that you use HMS to process push from native backend and you don't want to migrate all the code to use Infobip - there's still some use case where you want to send notifications directly to HMS. In that case you have your own service that extends HmsMessageService. Infobip's SDK also extends the same service and if your service is registered in manifest, Infobip's service won't be used for message handling (won't be able to receive notifications).

To solve this issue implement the following code in your Huawei messaging service:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // checking if received message is sent by Infobip and let it be processed
    if (MobileMessagingHmsService.onMessageReceived(this, remoteMessage)) {
        return;
    }
    // process non-Infobip notifications here
    // TODO your code
}

@Override
public void onNewToken(String token) {
    // forwarding necessary HMS token to Infobip's SDK
    MobileMessagingHmsService.onNewToken(this, token);
    // process HMS token here
    // TODO your code
}