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.
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 directly as shown below.
Installing using Artifact Id
Add the below dependency in the app/build.gradle file.
dependencies {
...
implementation("com.moengage:push-amp-plus:$sdkVersion")
}
replace $sdkVersion with the relevant SDK version.
VERSION COMPATIBILITYThe 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
<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.
<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() API of the MoEngage.Builder class to pass on the above information to the SDK.
val moEngage = MoEngage.Builder(this, "XXXXXXXX")
.configureMiPush(MiPushConfig([appId], [appkey],[enableTokenRegistration]))
.build()
MoEngage.initialise(moEngage)
MoEngage moEngage =
new MoEngage.Builder(this, "XXXXXXXXXX")
.configureMiPush(new 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.
<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 passPushToken() API to pass the push token to the MoEngage SDK
MoEMiPushHelper.getInstance().passPushToken(context, pushToken)
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 data to the SDK using the onNotificationClicked() API as shown below.
MoEMiPushHelper.getInstance().onNotificationClicked(context, message)
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:
MoEMiPushHelper.getInstance().isFromMoEngagePlatform(miPushMessage)
MoEMiPushHelper.getInstance().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 (MoEMiPushHelper.getInstance().isFromMoEngagePlatform(message)) {
MoEMiPushHelper.getInstance().onNotificationClicked(context, message)
}
}
NOTEMoEngage 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.
NOTEWhen 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 Payload
Push Token Callback
SDK provides a callback with the push token when SDK is registering for the push token. To get a callback implement the TokenAvailableListener interface and register for the callback using MoEMiPushHelper.getInstance().addTokenListener().
Non-MoEngage Callback
When using SDK's receiver com.moengage.mi.MoEMiPushReceiver SDK provides a callback if a push is received or clicked that is not sent from the MoEngage platform. To get a callback implement the NonMoEngagePushListener interface and register for the callback using MoEMiPushHelper.getInstance().addNonMoEngageListener().
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 |
---|---|
12.0.00 and later | 5.0.0 and later |