Skip to main content

Integrate Huawei push

Follow this guide to integrate Huawei Push Kit so the SDK can receive push notifications from Huawei Push Service.

Before integrating a third-party push provider, make sure you have configured the Android Application ID in the console. See Push Integration Overview.

Configure Huawei push in the console

To receive push notifications from the instant messaging service via Huawei Push, provide your Huawei Push app details in the console.

  1. Go to the Huawei AppGallery Connect website, click My projects, find your project in the project list, and select the app you want to view from the top navigation bar.

    As shown below, test-push is the project name and huawei-app-1 is an app linked to that project.

    (width=600)

    tip

    If you do not have a Huawei developer account or have not yet created a project and app, create an account, project, and app first. See the Huawei developer documentation for Creating an Account, Creating an App. Make sure the project has an app linked, that the push service is enabled, and that the signing certificate fingerprint is configured. If you have questions about configuring the push service in the Huawei console, see the official Huawei developer documentation for Configuring AppGallery Connect.

    Note the Client ID (same as App ID) and Client Secret for your app.

    (height=400)

  2. Open the Console, go to the Application Identifier page, click Set Push, find Android > Huawei Push, and enter the Client ID and Client Secret obtained in the previous step.

  3. (Optional) Configure a custom Intent for the notification click action. See the official Huawei developer documentation for Customizing the Click Action of a Notification Message.

    • The intent format must end with end.
    • After defining the intent, configure the corresponding intent-filter in the Activity entry in AndroidManifest.xml.
  4. (Optional) Configure the push badge count. See the official Huawei developer documentation for Badges.

    • badgeAddNum: The number added to the app badge — not the actual display count. Must be a positive integer less than 100. For example, if the app currently shows N unread messages and add_num is set to 3, each message sent increments the badge by 3, displaying N+3.
    • Activity: Full class path of the app entry Activity. Example: com.example.hmstest.MainActivity
  5. (Optional) Configure the default message self-classification identifier for the Huawei push channel, for example IM. This field takes effect after the app completes the self-classification entitlement application or applies for special permissions as required by Huawei. See the official Huawei Push documentation on Message Classification Standards. After configuration, all Huawei push notifications received under the current package name carry this field by default. Note that if the Huawei Push Category is specified when sending a message from the client or server, the per-message configuration takes precedence.

  6. Configure the Push Notification Title. Set the default push notification title. In general, this title is not used when the client sends messages that are converted to push notifications. When calling server-side push notification APIs without a notification title, the title configured here is used. If the sending user ID has no username on the server, this title is also used.

  7. Save your settings. All settings take effect 15 minutes after saving.

You have completed all required Huawei push configuration in the console. You can now set up client integration.

Configure the client to receive Huawei push

First, add the Huawei Push client SDK to your Android project.

Following the Huawei developer documentation for Integrating the HMS Core SDK, add the agconnect-services.json file to your app. Click agconnect-services.json to download the configuration file.

(height=400)

Place the downloaded agconnect-services.json file in the root directory of your app module, as shown below:

(height=250)

Import the Huawei push SDK

The Huawei Push client SDK must be fetched from the Huawei Maven repository. The repository configuration in Android Studio differs depending on whether you are using Gradle plugin 7.0 and below, 7.0, or 7.1 and above. See the official Huawei developer documentation for Integrating the HMS Core SDK — "Configuring the Maven Repository Address of the HMS Core SDK".

The example below uses Gradle plugin version below 7.0. Open the project-level build.gradle and add the following:

Groovy
allprojects {
repositories {
//Add Huawei Maven
maven {url 'http://developer.huawei.com/repo/'}
}
}

buildscript{
repositories {
//Add Huawei Maven
maven { url 'http://developer.huawei.com/repo/' }
}
dependencies {
// Add this line
classpath 'com.huawei.agconnect:agcp:1.6.1.300'
}
}
tip

You must add the AGC plugin configuration under buildscript > dependencies. See the official Huawei developer documentation for AGC Plugin Dependency to choose the appropriate AGC plugin version.

After adding the Huawei Maven repository, add the dependency in your app's build.gradle to include the Huawei Push client SDK. It is recommended to use the latest SDK version. For version information, see the official Huawei developer documentation on Push SDK Version Updates.

In the app module's build.gradle, add the following:

Groovy
android {
defaultConfig {
//...
manifestPlaceholders = [
HW_PUSH_ENABLE : "true"
]
}
}
dependencies {
// x.y.z is the current SDK version number
implementation 'ai.nexconn.chat:nexconn-push-hms:x.y.z'
}
...
// Add to the bottom of the file
apply plugin: 'com.huawei.agconnect'

tip

Huawei Push SDK dependency note: The latest Push SDK requires HMS Core (APK) version 4.0.0.300 or higher to be installed on the device. If the user's device does not have it installed, your app will automatically prompt the user to install HMS Core when it is needed.

Devices that support HMS Core (APK) by default include: some EMUI 4.0 and 4.1 devices, and Huawei devices running EMUI 5.0 or later.

Enable Huawei push service

After you complete the Huawei dependency and console configuration, initialize the SDK in your app. The SDK registers with Huawei Push Service and reports the obtained Huawei device token to the server.

ProGuard configuration

See the official Huawei Push documentation for Configuring Obfuscation Scripts.

Handle push notification click events

  • Customize push notification click events: Describes how to implement the SDK default navigation behavior and how to customize click event handling. See Handle Push Notification Click Events.
  • Customize push notification style: After the SDK receives a push notification from a third-party vendor, the displayed notification is a system notification popped up directly by the underlying OS, so customization is not supported.

Badge unread count

The SDK does not manage the app badge count, and the client SDK does not support controlling badge display.