CleverTap Xiaomi Push Integration
Learn how to integrate and send push notifications from Xiaomi.
Chinese OEMs command a considerable market share in the smartphone market. Many of these Chinese OEMs terminate processes running in the background and limit an app's ability to send push notifications to improve battery life. Due to this limitation, users are unable to receive important push notifications.
CleverTap can send push notifications powered by Xiaomi Cloud Push, an Android push notification delivery service for Chinese devices. We send a push notification through Xiaomi Cloud Push and Firebase Cloud Messaging (FCM) push services for a greater chance of delivery success. If a message is delivered through one of these push services, the notification from the other cloud service is suppressed. There is no priority defined, and there are no changes to the current flow of FCM. This ensures that the user will only receive the push notification once.
Register as a Xiaomi Developer
The first step to access the Xiaomi cloud push is to register as a Xiaomi developer on the Xiaomi Website.
Enter console and create an application
Once you log in to the console, click on Create App and enter the required details.


Get the app's Package name/App ID / AppKey / App Secret
Once the App is created on your console, click on the App name to get your Package Name/App ID/ App Key/ App Secret. Among these, the AppID and AppKey are the clientâs identity, used when the client SDK initializes; the AppSecret is authenticated for sending a message at the server-side.


Click on Mi Push Console and click on Enable Push to enable push services for your app.


IP Whitelisting
IP Whitelisting is not supported with Mi Push integration.
Integrate Xiaomi Push SDK
Download the SDK from the Xiaomi Website. The Android SDK is provided in a JAR library, so the third party app only needs to add a small number of codes to adapt to the Mi Push service.
Configure AndroidManifest.xml file
Configure with CleverTap Xiaomi plugin
It is easier to configure the Xiaomi push with our CleverTap plugin.
Step 1
Configure the AndroidManifest.xml file
<meta-data
android:name="CLEVERTAP_XIAOMI_APP_KEY"
android:value="@string/xiaomi_app_key" />
<meta-data
android:name="CLEVERTAP_XIAOMI_APP_ID"
android:value="@string/xiaomi_app_id" />
Step 2
Declare the Xiaomi App Key and your Xiaomi App ID in the res/strings.xml file.
<string name="xiaomi_app_key">Your Xiaomi App Key</string>
<string name="xiaomi_app_id">Your Xiaomi App ID</string>
Step 3
Add the following dependency in your app-level build.gradle file.
implementation 'com.clevertap.android:clevertap-xiaomi-sdk:1.2.0'
Configure Manually
Use the following steps if you do not wish to use the CleverTap plugin to configure the Xiaomi push.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<!-- the following 2 yourpackage should be changed to your package name -->
<permission
android:name="yourpackage.permission.MIPUSH_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="yourpackage.permission.MIPUSH_RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<service
android:enabled="true"
android:process=":pushservice"
android:name="com.xiaomi.push.service.XMPushService"/>
<service
android:name="com.xiaomi.push.service.XMJobService"
android:enabled="true"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
android:process=":pushservice" />
<!--NoteďźThis service must be added to the version 3.0.1 or laterďźincluding version 3.0.1ďź-->
<service
android:enabled="true"
android:exported="true"
android:name="com.xiaomi.mipush.sdk.PushMessageHandler" />
<service android:enabled="true"
android:name="com.xiaomi.mipush.sdk.MessageHandleService" />
<!--Noteďźthis service must be added to version 2.2.5 or later ďźincludes version 2.2.5ďź-->
<receiver
android:exported="true"
android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:exported="false"
android:process=":pushservice"
android:name="com.xiaomi.push.service.receivers.PingReceiver" >
<intent-filter>
<action android:name="com.xiaomi.push.PING_TIMER" />
</intent-filter>
</receiver>
Implement a BroadcastReceiver class
In order to receive messages, you must implement a BroadcastReceiver inherited from PushMessageReceiver and realize all required methods in it: onReceivePassThroughMessage, onNotificationMessageClicked, onNotificationMessageArrived, onCommandResult
, and onReceiveRegisterResult
, and then register your receiver in the AndroidManifest.xml
file. Method onReceivePassThroughMessage
is used to receive transparent messages sent by the server.
Pass token to CleverTap
In your MainActivityâs onCreate
method, pass the token to CleverTap using the following code:
MiPushClient.registerPush(this, APP_ID, APP_KEY);
String xiaomiToken = MiPushClient.getRegId(this);
if(cleverTapAPI != null){
cleverTapAPI.pushXiaomiRegistrationId(xiaomiToken,true);
}else{
Log.e(TAG,"CleverTap is NULL");
}
MiPushClient.registerPush(this, APP_ID, APP_KEY)
val xiaomiToken = MiPushClient.getRegId(this)
if (cleverTapAPI != null)
{
cleverTapAPI.pushXiaomiRegistrationId(xiaomiToken, true)
}
else
{
Log.e(TAG, "CleverTap is NULL")
}
Receive Push Notifications from CleverTap
In the onReceivePassThroughMessage
method, write the following code for CleverTap to render push notification and raise the Notification Viewed event.
@Override
public void onReceivePassThroughMessage(Context context, MiPushMessage message) {
try {
String ctData = message.getContent();
Bundle extras = Utils.stringToBundle(ctData);
CleverTapAPI.createNotification(context,extras);
} catch (JSONException e) {
e.printStackTrace();
}
}
fun onReceivePassThroughMessage(context:Context, message:MiPushMessage) {
try
{
val ctData = message.getContent()
val extras = Utils.stringToBundle(ctData)
CleverTapAPI.createNotification(context, extras)
}
catch (e:JSONException) {
e.printStackTrace()
}
}
From CleverTap Xiaomi SDK v1.2.0 onwards you can replace the above code with the following
@Override
public void onReceivePassThroughMessage(Context context, MiPushMessage message) {
CTXiaomiMessageHandler().createNotification(getApplicationContext(),message);
}
fun onReceivePassThroughMessage(context:Context, message:MiPushMessage) {
CTXiaomiMessageHandler().createNotification(applicationContext,message)
}
Update AppSecret / Package Name in Settings Dashboard


Updated about 2 months ago