Xiaomi Push(Mi)

This will guide you to integrate Xiaomi push notifications in Xiaomi android react native applications using SuprSend

This section is a step-by-step guide to integrating Xiaomi as your service provider for sending Android Push notifications. Integrating Xiaomi as your push vendor can increase your push delivery by around 30%. So, it is recommended to integrate Xiaomi as well as FCM for sending push notifications to your android devices.

Follow the below steps for the Xiaomi integration guide in your app:

Step-1: Create a Xiaomi App

The first step is to create a Xiaomi application on Mi portal. Once the app and project are created on the Xiaomi platform, you can get the Xiaomi tokens under "App management" -> "App info" which will be used for setting the Xiaomi push through SuprSend.


Step-2: Add Mi SDK to your project

1.1. Download the Xiaomi artifact(aar)

1.2. Create the libs folder inside your app module(android > app) and place the Xiaomi artifact(aar) that you downloaded in it.

1.3. Include this Xiaomi AAR in your app dependencies by adding below in your dependencies section of the app module.

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar","*.aar"])
}

Step-3: Permissions for Xiaomi integration

For integration with Xiaomi please register the below permission in your AndroidManifest.xml. These are the permissions that are required by Xiaomi SDK to work. Replace your_package_name with your package name in the below snippet.

<!--Xiaomi Starts - Sdk Needs this-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />

<permission
  android:name="<your_package_name>.permission.MIPUSH_RECEIVE"
  android:protectionLevel="signature" />

<uses-permission android:name="<your_package_name>.permission.MIPUSH_RECEIVE" />
<!--Xiaomi Ends-->

Step-4: Adding android components for Xiaomi integration

Below are the android components that are needed in your android AndroidManifest.xml.

<!--Xiaomi Starts-->
<receiver
  android:name="app.suprsend.xiaomi.SSXiaomiReceiver"
  android:exported="true">
  <intent-filter>
    <action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
  </intent-filter>
  <intent-filter>
    <action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" />
  </intent-filter>
  <intent-filter>
    <action android:name="com.xiaomi.mipush.ERROR" />
  </intent-filter>
</receiver>

<service
 android:name="com.xiaomi.push.service.XMJobService"
 android:enabled="true"
 android:exported="false"
 android:permission="android.permission.BIND_JOB_SERVICE"
 android:process=":pushservice" />

<service
 android:name="com.xiaomi.push.service.XMPushService"
 android:enabled="true"
 android:process=":pushservice" />

<service
 android:name="com.xiaomi.mipush.sdk.PushMessageHandler"
 android:enabled="true"
 android:exported="true" />

<service
 android:name="com.xiaomi.mipush.sdk.MessageHandleService"
 android:enabled="true" />

<receiver
 android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver"
 android:exported="true">
 <intent-filter>
   <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>
</receiver>

<receiver
 android:name="com.xiaomi.push.service.receivers.PingReceiver"
 android:exported="false"
 android:process=":pushservice">
 <intent-filter>
   <action android:name="com.xiaomi.push.PING_TIMER" />
 </intent-filter>
</receiver>
<!--Xiaomi Ends-->

Step-5: Initialize SuprSend SDK

Initialize Xiaomi push inside your SDK using SuprSend like below. Replace AppID and AppKey with your values which you can get as mentioned in Step 1.

public class MainApplication extends Application implements ReactApplication {

  @Override
  public void onCreate() {
  	super.onCreate();
    SSApi.Companion.initXiaomi(this, YourAppID, yourAppKey);
  }
}

Whatโ€™s Next

Add Xiaomi vendor configuration on SuprSend dashboard vendor page to start sending notification