Integrate the MiPush channel

更新时间:
复制 MD 格式

This topic describes how to integrate the MiPush channel SDK for Mobile Push.

Before you begin

Step 1: Add the SDK to your app

In your module-level (app-level) Gradle file, typically <project>/<app-module>/build.gradle, add the following SDK dependencies to the dependencies block.

Important
dependencies {
    implementation 'com.aliyun.ams:alicloud-android-third-push-xiaomi:x.x.x'
    implementation 'com.aliyun.ams:alicloud-android-third-push:x.x.x'
}
Note

The Mobile Push third-party channel SDK supports only Maven dependencies.

Step 2: Configure the SDK

1. Initialize the SDK

Important

You must initialize the SDK in the Application class after initializing the Mobile Push SDK. Otherwise, the MiPush channel registration may fail.

Initialize the SDK as follows:

// Kotlin
MiPushRegister.register(applicationContext, "YOUR_MIPUSH_APPID", "YOUR_MIPUSH_APPKEY")
// Java
MiPushRegister.register(applicationContext, "YOUR_MIPUSH_APPID", "YOUR_MIPUSH_APPKEY");

2. Configure obfuscation rules

If your project uses code obfuscation, add the following ProGuard rules for the MiPush channel.

# MiPush channel
-keep class com.xiaomi.** {*;}
-dontwarn com.xiaomi.**

Step 3: Verify the integration

1. Enable SDK logging

// Kotlin
val pushService = PushServiceFactory.getCloudPushService()
// For debug builds only. This line is not required for release builds.
pushService.setLogLevel(CloudPushService.LOG_DEBUG)
// Java
CloudPushService pushService = PushServiceFactory.getCloudPushService();
// For debug builds only. This line is not required for release builds.
pushService.setLogLevel(CloudPushService.LOG_DEBUG);      

2. Confirm successful integration

If the MiPush channel is initialized successfully, the following log is printed:

小米通道初始化成功日志

When a message is received through the MiPush channel, the following log is printed:

12-09 22:24:34.065 19566-25042/com.xxx D/MPS:MiPushReceiver: onReceiveMessage,msg=[{"f":262,"b":"{\"content\"\ ... ... ,"i":"f__-rnje3_OH74gE|VG0g3kwMnGADAGrXZku1FFW5"}]

3. Troubleshoot integration failures

If the MiPush channel registration fails (the registration success log is not displayed), check the system logs (set the logcat filter to No Filters).

Filter the logs with the regular expression PushService|BroadcastQueue. The following screenshots show examples:

  • MiPushBroadcastReceiver is not configured:

  • The MIPUSH_RECEIVE permission is not configured:

Next steps

You can now send notifications to the notification bar through the MiPush channel from the EMAS console. However, to handle notification taps, you must use the auxiliary pop-up window to receive push data. For details, see Integrate the auxiliary pop-up window.

Important
  • When you send a push notification through a third-party channel with Mobile Push, either in the EMAS console or via an API call, you must configure server-side parameters as described in the auxiliary pop-up window documentation. Otherwise, notifications are not sent through the third-party channel.

  • The auxiliary pop-up window for MiPush is supported in Android SDK V2.3.0 and later.

Third-party channel FAQ