Skip to main content

Configure for HMS

This section is relevant only if you are building application for HMS and Huawei AppGallery.

Huawei Mobile Services (HMS) is the equivalent of Google Mobile Services (Play services) for manufactures (mainly Huawei) which don't have access to Google software products. HMS comes pre-installed on Huawei devices, but it can be installed on any Android device, even alongside Google Mobile Services.

MeaWallet has built an MTP SDK version for using on devices with HMS. Make sure you have completed steps described in installation and implementation guide. Further parts in this section describes only the steps and actions that are different from generic steps described before or steps that are specific to HMS only.

Packaging and delivery

MTP SDK for HMS is built and packaged in a separate library archive file with a different filename (has hms in it). It has to be explicitly included as a new dependency.

Preparation for onboarding

There are two values that needs to be shared with MeaWallet during key exchange in onboarding process. Once your HMS app is created in Huawei Developer portal, find and share App ID and App secret.

HMS App Id and secret

Installation

Gradle Configuration

HMS MTP SDK is added to the project as a dependency, library is hosted in a private Maven repository, so you need to configure build.gradle by configuring the assigned URL and credentials. If you have already added the private Maven repository while adding a regular MTP SDK dependency, you don't have to do it again. Visit generic installation section for examples on dependency naming.

MeaWallet suggests having separate build variants (e.g. using flavors) for HMS and regular MTP SDK and never including both SDKs in the same build and output file.

Refer to Huawei documentation on additional gradle configurations and plugins necessary for HMS.

App Manifest

Add reference to receivers.MyHmsListenerService service which extends from HmsMessageService. See app manifest for an example.

Implementation guide

HMS MTP SDK and regular MTP SDK has the same public interface. It means 100% interactions between application and MTP SDK remains the same regardles which moblie service suite is used. The only difference is how issuer application communicates to Push Service provider API in order to acquire messaging token and receive mesages.

Acquire PushKit Token / Update Device Info

In case of HMS, token is acquired and updated with the same flow. Use MeaTokenPlatform.isRegistered() for determining whether to register device or update device info.

info

There is a difference in how a device token is acquired among different versions of EMUI. EMUI below version 10 acquires token differently. Approach demonstrated below is how we managed to get it work with all EMUI versions the same way.

public class MyHmsListenerService extends HmsMessageService {

...

/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is also called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
@Override
public void onNewToken(String newToken) {
...

// Devices with EMUI less than 10.0 can't receive ID token directly from getToken(). Instead
// token is sent to onNewToken callback and has to be processed there.
try {
if (!MeaTokenPlatform.isRegistered()) {

registerPlatform(newToken);
} else {

updateDeviceInfo(newToken);
}
} catch (NotInitializedException error) {

...
}
}

...

private void registerPlatform(String token) {
sAsyncRegisterState.postValue(AsyncRegisterState.STARTED);

MeaTokenPlatform.register(token, "en", new MeaListener() {
@Override
public void onSuccess() {

...
}

@Override
public void onFailure(@NonNull MeaError error) {

...
}
});
}

private void updateDeviceInfo(String token) {

MeaTokenPlatform.updateDeviceInfo(token, null, new MeaListener() {
@Override
public void onSuccess() {

...
}

@Override
public void onFailure(@NonNull MeaError error) {

...
}
});
}
}

Registration

info

Issuer app should be enabled for Huawei PushKit: Set up an HMS client app on Android.

After setting up HMS and acquiring PushKit messaging token, pass the value as pushServiceInstanceIdToken to MeaTokenPlatform.register(...) method.

Forward Remote Push Messages

If card digitization request is successful then the Credential Management System - Dedicated (CMS-D) sends a push notification and application should pass this notification to MTP SDK using MeaTokenPlatform.Rns.onMessageReceived(...) method.

public class MyHmsListenerService extends HmsMessageService {

@Override
public void onMessageReceived(final RemoteMessage message) {

Map<String, String> messageData = message.getDataOfMap();

...
if (!MeaTokenPlatform.Rns.isMeaRemoteMessage(messageData)) {

return;
}


if (MeaTokenPlatform.Rns.isMeaTransactionMessage(messageData)) {

MeaTransactionMessage transactionMessage = MeaTokenPlatform.Rns.parseTransactionMessage(messageData);

...
} else {

MeaTokenPlatform.Rns.onMessageReceived(messageData);
}
}
}