Integrate Xiaomi Push
Follow this guide to integrate Xiaomi Mi Push for the Chinese or international version, enabling RC SDK to support Xiaomi Push.
Before integrating third-party push services, ensure that the Android Application ID has been configured in the Console. For more details, refer to Push Integration Overview.
IMLib SDK has supported Xiaomi International Push Service since version 5.6.8.
Configure Xiaomi Push in the Console
If you want to receive push notifications from the RC server via the Xiaomi Push channel, you need to provide detailed information about your Xiaomi Push application in the Console.
-
Go to the Xiaomi Developer Platform, select the Xiaomi application corresponding to your current project, click Application Info, and record the AppID, AppKey, and AppSecret.
tipIf you don't have a Xiaomi developer account or haven't created an application yet, refer to the Xiaomi Push documentation:
- Mainland China - Push Service Activation Guide
- International Version - Push Service Activation Guide. Currently, Xiaomi has data centers in Mumbai, India; Frankfurt, Germany; Moscow, Russia; and Singapore. Please choose the appropriate region to create your application.
The AppSecret is the identity credential for the Xiaomi Push server. It is used when sending messages from the Xiaomi Push server SDK to the client and needs to be provided to RC in the Xiaomi Push configuration in the Console. The AppId and AppKey are the identity credentials for the Xiaomi Push client and will be provided to the RC SDK later when enabling the Xiaomi Push service for initializing the Xiaomi Push client SDK.
-
Open the Console, go to the Application Identifier page. Click Set Push, find Android > Xiaomi Push, and enter the AppSecret obtained in the previous step.
-
(Optional) Configure the Xiaomi Push Notification Title. Set the default push notification title. Generally, this title setting is not used when the client sends a message converted to Push. When calling the RC server API
/push.json
,/push/user.json
, or/push/custom.json
to send push notifications, if no notification title is passed in, the title set here will be used. When sending messages from the server, if the sender's user ID does not have a username on the RC server, this "Push Notification Title" will also be used. -
Select the Push Channel Type. Xiaomi Push message types are divided into normal messages and notification messages. Refer to the Xiaomi Push Message Restrictions Document.
- Normal messages, the default Xiaomi Push channel used by RC, have restrictions.
- Notification messages, no restrictions. Requires the channelId applied for in the Xiaomi backend.
-
Save the settings. All settings will take effect after 30 minutes.
You have completed all the necessary Xiaomi Push configuration in the Console. Now you can proceed to set up client integration.
Configure the Client to Receive Xiaomi Push
Important
It is recommended to configure Xiaomi's App ID and App Key via
gradle.properties
. If you wish to write the configuration directly in the App'sbuild.gradle
, be sure to add escape characters, as shown below:
XIAOMI_APP_ID: "\"1882303761517473625\""
XIAOMI_APP_KEY : "\"1451747338625\""
.
You can integrate Xiaomi Push using either of the following methods:
-
Method 1: Configure Xiaomi's App ID and App Key via
gradle.properties
. In thebuild.gradle
file, undermanifestPlaceholders
, reference thegradle.properties
configuration file for theXIAOMI_APP_ID
andXIAOMI_APP_KEY
fields.Example
gradle.properties
configuration:MI_PUSH_APPID="9882303761517473625"
MI_PUSH_APPKEY="9451747338625"
Example build.gradle
configuration:
android {
defaultConfig {
manifestPlaceholders = [
// Xiaomi-related application parameters
XIAOMI_APP_ID : "${MI_PUSH_APPID}",
XIAOMI_APP_KEY : "${MI_PUSH_APPKEY}",
]
}
// ...Other configurations
}
-
Method 2: Add dependencies in the App's
build.gradle
.Note If you wish to write the configuration directly in the App's build.gradle, be sure to add escape characters, as shown below:
android {
defaultConfig {
manifestPlaceholders = [
// Xiaomi-related application parameters
XIAOMI_APP_ID : "\"9882303761517473625\""
XIAOMI_APP_KEY : "\"9451747338625\"",
]
}
// ...Other configurations
}Complete the corresponding configuration based on the region of the Xiaomi Push service:
-
Mainland China: Integrate the Xiaomi Push client for Mainland China and configure Xiaomi's
XIAOMI_APP_ID
andXIAOMI_APP_KEY
.android {
defaultConfig {
//...
manifestPlaceholders = [
XIAOMI_APP_ID : "xxxxxxxx",
XIAOMI_APP_KEY: "xxxxxxxx"
]
}
}
dependencies {
// x.y.z is the current IM SDK version number
implementation 'cn.rongcloud.sdk.push:xiaomi:x.y.z'
} -
International Regions: Xiaomi has data centers in Mumbai, India; Frankfurt, Germany; Moscow, Russia; and Singapore. If you are using Xiaomi's international push service, you must integrate the Xiaomi Push client for international regions and configure Xiaomi's
XIAOMI_APP_ID
,XIAOMI_APP_KEY
, and region.android {
defaultConfig {
//...
manifestPlaceholders = [
XIAOMI_APP_ID : "xxxxxxxx",
XIAOMI_APP_KEY: "xxxxxxxx",
XIAOMI_APP_REGION : "" // Global, Europe, Russia, India
]
}
}
dependencies {
// x.y.z is the current IM SDK version number
implementation 'cn.rongcloud.sdk.push:xiaomi_global:x.y.z'
}
-
Enable Xiaomi Push Service
Before initializing the SDK, call the following code to initialize the RongPushPlugin
module.
RongPushPlugin.init(getContext());
If the RongPushPlugin
module cannot be found, check if you have already Integrated RC's Self-built Push Channel.
Obfuscation Configuration
If your application uses obfuscation, you can use the following obfuscation configuration:
-dontwarn com.xiaomi.mipush.sdk.**
-keep public class com.xiaomi.mipush.sdk.* {*; }
Handle Push Notification Click Events
- Customize Push Notification Click Events: Learn how to implement the SDK's default jump behavior and how to customize the click event handling. For more details, refer to Customize Push Notification Click Events.
- Customize Push Notification Styles: When the SDK receives push notifications from other third-party vendors, the notifications are system notifications directly popped up by the underlying system, so customization is not supported.