push huawei - optimove-tech/Optimove-SDK-Android GitHub Wiki

Configuring HCM for Huawei Devices

The latest Huawei handsets such as the P40 family of phones do not use FCM for push notifications and instead use Huawei Cloud Messaging (HCM). If you want to message all of your Android users, including those using Huawei phones, then in addition to FCM you also need to configure HCM as described in this section. After completing the FCM configuration, you also need to:

  1. Set up an app on the Huawei Mobile Developer Console
  2. Configure Push in the Mobile Marketing UI
  3. Add Huawei Mobile Services dependencies, files, and plugins to your project
  4. Add Huawei-specific manifest entries

All other push behavior & customization works identically to FCM.

To begin, configure a project on the Huawei Developer Console, and enable the Push feature by following the Push Kit developer guide step 1.

Note that your app needs a valid signing configuration for both debug and release builds. The SHA-256 fingerprint of your signing key is required to match the Huawei app configuration prior to continuing.

Once you have created the app, configure the HCM gateway in your Mobile Marketing UI. Expand 'Messaging' in the left menu and select 'Configuration' and click the cog next to the Huawei icon.

You need to enter the App ID and App Secret from the Huawei Developer Console.

Once configured, now add the agconnect-services.json file (downloaded from the Huawei developer console) to your Android application directory.

Next, add the Huawei repository and plugin dependency to your root build.gradle:

buildscript {
    repositories {
        ...
        maven {
            url 'https://developer.huawei.com/repo/'
        }
    }
    dependencies {
        ...
        classpath 'com.huawei.agconnect:agcp:1.2.1.301'
    }
}

allprojects {
    repositories {
        ...
        maven {
            url 'http://developer.huawei.com/repo/'
        }
    }
}

Next, in your app-level build.gradle, add the HMS Push Kit dependency and apply the HMS plugin:

dependencies {
    ...
    implementation 'com.huawei.hms:push:6.1.0.300'
}

// Add to bottom of file
apply plugin: 'com.huawei.agconnect'

Finally, add the HMS push service to your AndroidManifest.xml:

<!-- Optimove HMS Messaging Service -->
<service
    android:name="com.optimove.android.optimobile.HmsMessagingService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
    </intent-filter>
</service>

Push registration should be performed as with FCM.

Huawei Troubleshooting

  • Ensure the app signing key fingerprint matches in the Huawei developer console
  • Ensure the app package matches the configuration in the Huawei developer console
  • Ensure the Push Kit service is enabled for your app in AppGallery Connect > App > Develop > Grow > Push Kit. You must enable the service and choose a data storage location.
⚠️ **GitHub.com Fallback** ⚠️