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.
For more information, refer to Configuring Xiaomi Push on MoEngage.
info |
Note If you are already using an older push-amp-plus SDK, refer to the Migration Guide before updating the integration to the latest version. |
SDK Installation
Installing using Catalog
Integration using a Version Catalog is the recommended way of integration, refer to the Configure Version Catalog document to configure a catalog if not done already. Once you have configured the catalog add the dependency in the app/build.gradle file as shown below
dependencies {
...
implementation(moengage.pushAmpPlus)
}
Alternatively, you can add the dependency using Artifact ID as described in Installation using Artifact ID. However, installation using Catalog ID is the recommended approach as installing using Artifact ID may lead to version mismatch if mapped incorrectly.
Add dependency of Mi SDK
Download the Mi SDK from here and it to the libs folder of the application module of your project.
Add the below configuration in the build.gradle of the app module.
android {
...
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', "*.aar"])
...
}
If you are using the new project structure i.e. structure applicable from the Android Gradle plugin version 7.0.0 and above, add the following in the dependencyResolutionManagement block of your settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
// add the below in your project.
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
google()
mavenCentral()
}
}
Add MoEngage Files
- Download the MoEngage files from here.
- Create a package with the name com.moengage.push.amp.plus
- Paste the downloaded files in the above package.
Push handled by the MoEngage SDK
Add Reciever in the Manifest file
If you want the MoEngage SDK to handle token registration and push notifications, add the following receiver to your application's AndroidManifest.xml.
<receiver
android:name="com.moengage.push.amp.plus.MiPushReceiver"
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>
Initialising Mi Push
To initialize Push Amp Plus call the below API when the application comes to the foreground.
MiPushHelper.initialiseMiPush(context, appKey, appId, region)
MiPushHelper.INSTANCE.initialiseMiPush(context, appKey,appId, region);
where
appKey - App-Key from the Mi Dashboard.
appId - App-Id from the Mi Dashboard.
region - The region in which the Mi data should reside. Set the region using the Region enum from the Mi SDK.
Refer to the Github Sample for a reference implementation.
Push 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 passPushToken() API to pass the push token to the MoEngage SDK
MoEMiPushHelper.getInstance().passPushToken(context, pushToken)
MoEMiPushHelper.getInstance().passPushToken(context, pushToken);
Setup Region
Set the region in which the Mi data resides. To fetch the region of the token call MiPushClient.getAppRegion(context) API. Pass the region(String returned from the API) to the below API.
MiPushHelper.setDataRegion(context, region)
MiPushHelper.INSTANCE.setDataRegion(context, region);
where,
region - The region in which the Mi data should reside.
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 data to the SDK using the onNotificationClicked() API as shown below.
MiPushHelper.getInstance().onNotificationClicked(context, message)
MiPushHelper.getInstance().onNotificationClicked(context, message);
This API is responsible for inflating the desired Activity of click. Please ensure this API is called on the main thread.
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:
MiPushHelper.isFromMoEngagePlatform(miPushMessage)
MiPushHelper.INSTANCE.isFromMoEngagePlatform(miPushMessage);
So the final implementation of the onNotificationMessageClicked() as described:
override fun onNotificationMessageClicked(context: Context?, message: MiPushMessage?)
if (message == null || context == null) {
return
}
if (MiPushHelper.getInstance().isFromMoEngagePlatform(message)) {
MiPushHelper.onNotificationClicked(context, message)
}
}
info |
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 tokens, 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.
info |
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. |