Xiaomi Push (Mi)

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

This section is a step-by-step guide to integrate 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 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(mapOf("dir" to "libs", "include" to listOf("*.jar","*.aar"))))
}

Step-3: Give App 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="app.suprsend.android.permission.MIPUSH_RECEIVE"
            android:protectionLevel="signature" />

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

Step-4: Add required android components for Xiaomi integration

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

<!--Xiaomi Starts-->
<!--Suprsend Receiver 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>
<!--Suprsend Receiver Ends-->

<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

You can register with xiaomi push service by iniatilizing the suprsend sdk instance with below api. For that you will need AppID & AppKey taken from xiaomi dashboad.
Please follow step 1 & 2 to generate app id & key.


class MyApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        SSApi.initXiaomi(context = this, appId = "AppID", apiKey = "AppKey")
    }
}


Whatโ€™s Next

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