Integrate Huawei Push
Follow this guide to integrate Huawei Push Kit and enable RC SDK to receive push notifications from Huawei Push Service.
Before integrating third-party push services, ensure that you have configured the Android Application ID in the RC Console. For details, refer to Push Integration Overview.
Configure Huawei Push in RC Console
To receive push notifications from RC IM services via Huawei Push, you need to provide details of your Huawei Push application in the RC Console.
-
Go to the Huawei AppGallery Connect website, click My Projects, find your project in the project list, and select the application for which you want to view information in the top navigation bar.
As shown in the figure below,
test-push
is the project name, andhuawei-app-1
is the application associated with this project.tipIf you do not have a Huawei developer account or have not created a project and application, please create an account, project, and application first. For details, refer to the Huawei developer documentation Create Account, Create Application. Ensure that the application is associated with the project, the push service is enabled, and the signature certificate fingerprint is configured. If you have any questions about the process of configuring the push service on the Huawei Console, refer to the official Huawei developer documentation Configure AppGallery Connect.
You need to record the Client ID (same as App ID) and Client Secret under the Application.
-
Open the RC 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.
-
(Optional) Configure the Intent for customizing the click action of the message. For details, refer to the official Huawei developer documentation Customize Click Action.
- Note that the intent format must end with
end
. - After customizing the intent, configure the following
intent-filter
in the Activity ofAndroidManifest.xml
according to the defined intent.
- Note that the intent format must end with
-
(Optional) Configure the push badge count. For details, refer to the official Huawei developer documentation Desktop Badge.
- badgeAddNum: The badge add number is not the actual display number of the application badge but an integer greater than 0 and less than 100. For example, if an application currently has N unread messages and the add_num is set to 3, each message sent will increase the badge display number by 3, resulting in N+3.
- Activity: The full path of the application entry Activity class. Example:
com.example.hmstest.MainActivity
-
(Optional) Configure the default message self-classification identifier for the Huawei Push channel, such as
IM
. The field is valid after the app completes the Self-Classification Rights Application or Apply for Special Permissions as required by Huawei. For details, refer to the official Huawei Push documentation Message Classification Standards. After successful configuration, all Huawei push notifications received by the current package name will carry this field by default. Note that if the Huawei Push Category is configured when the client or server sends a message, the configuration specified at the time of sending the message will be used. -
Configure the Push Notification Title. Set the default push notification title. Generally, this title setting is not used when the client sends a message and converts it to Push. When calling the RC server API
/push.json
,/push/user.json
,/push/custom.json
to push notifications, if the notification title is not passed in, the title set here will be used. When sending a message from the server, if the user ID sent does not have a username in the RC server, this "Push Notification Title" will also be used. -
Save the settings. All settings will take effect after 30 minutes.
You have completed all the necessary Huawei Push configurations in the RC Console. Now you can proceed to set up client integration.
Configure the Client to Receive Huawei Push
First, you need to add the Huawei Push client SDK to your Android project.
According to the Huawei developer documentation Integrate HMS Core SDK, you need to add the "agconnect-services.json" file to your app. Click agconnect-services.json to download the configuration file.
Place the downloaded agconnect-services.json
file in the root directory of the app module, as shown below:
Import Huawei Push SDK
The Huawei Push client SDK needs to be obtained from the Huawei Maven repository. The code repository configuration in Android Studio differs for Gradle plugin versions below 7.0, 7.0, and 7.1 and above. For details, refer to the official Huawei developer documentation Integrate HMS Core SDK under "Configure HMS Core SDK Maven Repository Address".
This step uses Gradle plugin versions below 7.0 as an example. Open the build.gradle
file in the project and add the following content.
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'
}
}
Under "buildscript > dependencies", you need to add the AGC plugin configuration. Please refer to the official Huawei developer documentation AGC Plugin Dependency Relationship to select the appropriate AGC plugin version.
After adding the Huawei Maven repository, you can add dependencies in the app's build.gradle
to directly introduce the Huawei Push client SDK. It is recommended that you integrate the SDK with the latest version number. For version number index, refer to the official Huawei developer documentation Push Service SDK Version Update Notes.
Add the following content to the build.gradle
file in the app module:
android {
defaultConfig {
//...
manifestPlaceholders = [
HW_PUSH_ENABLE : "true"
]
}
}
dependencies {
// x.y.z is the current IM SDK version number
implementation 'cn.rongcloud.sdk.push:huawei:x.y.z'
}
...
// Add to the bottom of the file
apply plugin: 'com.huawei.agconnect'
Huawei Push SDK Dependency Note: The latest version of the Push SDK requires HMS Core (APK) version 4.0.0.300 or higher to be installed on the terminal device; if the user's phone does not have it installed, your app will automatically prompt the user to install it when calling HMS Core.
Devices that support HMS Core (APK) by default include: some EMUI 4.0 and 4.1 phones, and Huawei phones with EMUI 5.0 and later.
Enable Huawei Push Service
Please enable the Huawei Push service before initializing the RC SDK. The RC SDK will register with the Huawei Push service and report the obtained Huawei Push Token to the RC server.
Before SDK initialization, call the following code to initialize the RongPushPlugin
module.
RongPushPlugin.init(getContext());
If the RongPushPlugin
module cannot be found, please check if you have Integrated RC Self-Built Push Channel.
Obfuscation Configuration
Please refer to the official Huawei Push documentation Configure Obfuscation Script.
Handle Push Notification Click Events
- Customize Push Notification Click Event: Introduces how to implement the SDK's default jump behavior and how to customize the click event handling. For details, refer to Customize Push Notification Click Event.
- Customize Push Notification Style: The notification popped up by the SDK after receiving push notifications from other third-party vendors is a system notification, which is directly popped up by the underlying system of the phone, so customization is not supported.
Badge Unread Count
RC does not maintain the application badge count, and the RC client SDK does not support controlling the badge display. For information on the implementation of badge control related to vendor push notifications, refer to the knowledge base document Push Badge.