Configuring Xiaomi Push

For more information about using the Push Amp Plus version below 2.0.00, refer to the Push Amp Plus Legacy documentation.

Configure your account on MoEngage

Navigate to the Settings Page Dashboard --> Settings --> Channel --> Push --> Mobile Push --> Push Amp+ on the MoEngage Dashboard and add the Xiaomi Push Settings under the Push Amp+ Tab.

b023c17-Screenshot_2020-09-09_at_1.44.00_PM.png

For more information, refer to Configuring Xiaomi Push on MoEngage.

SDK Installation

Add the below dependency in the app/build.gradle file.

build.gradle
implementation("com.moengage:push-amp-plus:$sdkVersion")

replace $sdkVersion with the relevant SDK version.

We recommend integrating the MoEngage Dependency Catalog to easier dependency management. Refer to the documentation to know more.

 

VERSION COMPATIBILITY

The push-amp-plus artifact should be compatible with the moe-android-sdk artifact you have already added. Ensure you check the version compatibility using the following table and pick the right version for your application.

Add Permissions in Manifest File

Add the below permissions in your applications Manifest file

AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission
	android:name="${applicationId}.permission.MIPUSH_RECEIVE"
	android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.MIPUSH_RECEIVE" />

Add Receivers and Services in the Manifest File

Add the following receiver and services in your application's manifest file.

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

<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.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>

Add Meta Data

To use Push Amp Plus you need to provide the App Key, App Id from the Mi Console to the MoEngage SDK. For more information about finding keys, refer to Configuring Xiaomi Push on MoEngage to know about it.
Use configureMiPush() of the MoEngage.Builder class to pass on the above information to the SDK.

Kotlin Java
val moEngage = MoEngage.Builder(this, "XXXXXXXX")
        .configureMiPush(MiPushConfig([appId], [appkey],[enableTokenRegistration]))
        .build()
    MoEngage.initialise(moEngage)

enableTokenRegistration - This parameter tells the SDK whether SDK should register for push token or your application would be taking care of the same.

Configuring Receivers

Push Registration handled by the MoEngage SDK

If you want the MoEngage SDK to handle token registration and push notification, add the following receiver to your applications AndroidManifest.xml.

AndroidManifest.xml
<receiver
    android:name="com.moengage.mi.MoEMiPushReceiver"
    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>

Push Registration handled by the Application

If the application is handling token registration and notification via its own receiver the application would have to pass on the Push token and the `MiPushMessage` received on notification click to the MoEngage SDK.

Pass the Push token

Use the following API to pass the push token to the MoEngage SDK

Kotlin Java
MoEMiPushHelper.getInstance().passPushToken(context, pushToken)

Pass Callback on Notification Click

Use the below API to pass the notification click callback to the MoEngage SDK.
You would need to override the onNotificationMessageClicked() of the PushMessageReceiver class and pass the callback to the SDK.

Kotlin Java
MoEMiPushHelper.getInstance().onNotificationClicked(context, message)

If you have multiple providers sending push notifications make sure you check if the notification is sent from the MoEngage platform or not using the following API:

Kotlin Java
MoEMiPushHelper.getInstance().isFromMoEngagePlatform(miPushMessage)

So the final implementation of the onNotificationMessageClicked() as described:

Kotlin
    override fun onNotificationMessageClicked(context: Context?, message: MiPushMessage?) 
        if (message == null || context == null) {
            return
        }
        if (MoEMiPushHelper.getInstance().isFromMoEngagePlatform(message)) {
            MoEMiPushHelper.getInstance().onNotificationClicked(context, message)
        }
    }
 

NOTE

MoEngage SDK takes care of re-directing the user to the selected screen or deep-link, do not add any logic for redirection.

Guidelines for token registration

If you are application is handling push token then please follow the guidelines

  • Register for Mi Push only if the device manufacturer is Xiaomi.
  • Register for Mi Push only if the device has MIUI. You can use the helper API provided by MoEngage SDK to check whether the device has MIUI installed, use MoEMiPushHelper.getInstance().hasMiUi().
  • Add a retry mechanism in case of push registration failure.
 

NOTE

When you register MoEngage SDK all the above is taken care of. MoEngage recommends that you let MoEngage SDK register for the push token.

Callbacks

When the application is using MoEngage SDK's receiver the SDK optionally provides callbacks to the application in the following cases

  • Push Token is available
  • Non-MoEngage pass through message is received
  • Non-MoEngage Notification Clicked

To get the callback application needs to implement the MiPushEventListener API Reference.
To register a listner use MoEMiPushHelper.getInstance().addEventListener() API. As these callbacks can be triggered when the application is in background register the listener in the onCreate() of the Application class.

Version Compatibility

The push-amp-plus artifact or module is dependent on the Core SDK or moe-android-sdk artifact or module.
Based on the version of the Core SDK you are using choose the right version of the Push-Amp Plus module.

Core SDK Version Push Amp Plus Version
11.2.00 and later 3.2.00 and later
11.1.00 3.1.00
11.0.03 - 11.0.05 3.0.01, 3.0.02
11.0.01 - 11.0.02 3.0.00
10.6.00 2.2.00
10.4.00 - 10.5.00 2.1.00
10.3.00 - 10.3.02 2.0.00
10.2.01 - 10.2.02 1.2.00
10.1.01 - 10.2.00 1.1.01
10.0.00 - 10.0.03 1.0.00
9.8.02 - 9.8.04 0.5.00
9.7.03 - 9.8.01 0.4.00
9.7.01 - 9.7.02 0.3.00
9.6.00 - 9.7.00 0.2.00

 

Was this article helpful?
0 out of 0 found this helpful