Android MA Function Integration Guide
Last updated:2025-03-18
Usage Tips
To use the MA function of the EngageLab SDK, you need to integrate the AppPush module at the same time. Please create an application on the AppPush platform first to obtain the AppKey.
1. Importing Packages in libs
- Manual Method
Import mt-sdk-x.x.x-engagelab.aar under the libs package into the libs directory
Import mt-sdk-ma-x.x.x.aar under the libs package into the libs directory
Import mt-sdk-x.x.x-engagelab.aar under the libs package into the libs directory
Import mt-sdk-ma-x.x.x.aar under the libs package into the libs directory
This code block in the floating window
- Automatic Method
dependencies {
// Necessary, main package
implementation 'com.engagelab:engagelab:5.0.0' // Taking version 5.0.0 as an example here.
// Optional, ma function
implementation 'com.engagelab.plugin:oth_ma:5.0.0' // Taking version 5.0.0 as an example here.
}
dependencies {
// Necessary, main package
implementation 'com.engagelab:engagelab:5.0.0' // Taking version 5.0.0 as an example here.
// Optional, ma function
implementation 'com.engagelab.plugin:oth_ma:5.0.0' // Taking version 5.0.0 as an example here.
}
This code block in the floating window
2. build.gradle Configuration
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// app packageName, which needs to be the same as that on the console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// appKey, which needs to be the same as that on the console and has a one-to-one relationship with the packageName
ENGAGELAB_PRIVATES_APPKEY : "Your appkey",
// Engagelab appChannel, used for channel statistics
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelab process, the process where the Engagelabsdk works. Note: the beginning
ENGAGELAB_PRIVATES_PROCESS: ":remote"
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// app packageName, which needs to be the same as that on the console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// appKey, which needs to be the same as that on the console and has a one-to-one relationship with the packageName
ENGAGELAB_PRIVATES_APPKEY : "Your appkey",
// Engagelab appChannel, used for channel statistics
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelab process, the process where the Engagelabsdk works. Note: the beginning
ENGAGELAB_PRIVATES_PROCESS: ":remote"
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
This code block in the floating window
3. Creating Necessary Components
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* Developers inherit from MTCommonService, which can keep the long connection alive for a longer time
* <p>
* An empty implementation is sufficient.
*/
public class UserService extends MTCommonService {
}
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* Developers inherit from MTCommonService, which can keep the long connection alive for a longer time
* <p>
* An empty implementation is sufficient.
*/
public class UserService extends MTCommonService {
}
This code block in the floating window
package com.engagelab.app.component;
import android.content.Context;
import android.widget.Toast;
import java.util.Arrays;
import com.engagelab.app.common.ExampleGlobal;
import com.engagelab.app.listener.StatusObserver;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.common.component.MTCommonReceiver;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.core.api.WakeMessage;
import com.engagelab.privates.push.api.CustomMessage;
import com.engagelab.privates.push.api.MobileNumberMessage;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.api.PlatformTokenMessage;
/**
* Developers inherit from MTCommonReceiver and can obtain the method callbacks of the SDK
* <p>
* All callbacks are in the main thread.
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* Long connection status callback
*
* @param context Not null
* @param enable Whether it is connected
*/
@Override
public void onConnectStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onConnectState:" + enable);
if (enable) { // As long as the long connection is successful once, it can be called anywhere later
MTMAApi.getInstance(this).start(new CallBack() {
@Override
public void onCallBack(int code, String msg) {
Log.e(TAG, "start code:" + code);
Log.e(TAG, "startmsg:" + msg);
}
});
}
}
}
package com.engagelab.app.component;
import android.content.Context;
import android.widget.Toast;
import java.util.Arrays;
import com.engagelab.app.common.ExampleGlobal;
import com.engagelab.app.listener.StatusObserver;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.common.component.MTCommonReceiver;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.core.api.WakeMessage;
import com.engagelab.privates.push.api.CustomMessage;
import com.engagelab.privates.push.api.MobileNumberMessage;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.api.PlatformTokenMessage;
/**
* Developers inherit from MTCommonReceiver and can obtain the method callbacks of the SDK
* <p>
* All callbacks are in the main thread.
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* Long connection status callback
*
* @param context Not null
* @param enable Whether it is connected
*/
@Override
public void onConnectStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onConnectState:" + enable);
if (enable) { // As long as the long connection is successful once, it can be called anywhere later
MTMAApi.getInstance(this).start(new CallBack() {
@Override
public void onCallBack(int code, String msg) {
Log.e(TAG, "start code:" + code);
Log.e(TAG, "startmsg:" + msg);
}
});
}
}
}
This code block in the floating window
4. AndroidManifest.xml Configuration
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.engagelab.app">
<!-- Necessary, network permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional, notification vibration -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.engagelab.app.MainApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MT"
android:usesCleartextTraffic="true"
tools:targetApi="m"> <!-- If using http requests, then using http needs to be allowed -->
.....................................................................................................
<!-- Since this class has the long connection function, the service with the Engagelab word in the package name may be directly killed during the power-saving optimization by the mobile phone manufacturer -->
<!-- Therefore, developers need to inherit from com.engagelab.app.component.MTCommonService to improve the survival rate of the long connection, so as to achieve the purpose of increasing the message arrival rate -->
<service
android:name="com.engagelab.app.component.UserService"
android:exported="false"
android:process="${ENGAGELAB_PRIVATES_PROCESS}">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_SERVICE" />
</intent-filter>
</service>
<!-- Used to receive the callbacks of Engagelab services, including long connection status/notification switch status/notification message arrival/notification message click/notification message deletion/custom message/vendor token callback -->
<!-- There is no need to configure a sub-process. This callback is in the main process, which is convenient for business operations -->
<receiver
android:name="com.engagelab.app.component.UserReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_RECEIVER" />
</intent-filter>
</receiver>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.engagelab.app">
<!-- Necessary, network permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional, notification vibration -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.engagelab.app.MainApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MT"
android:usesCleartextTraffic="true"
tools:targetApi="m"> <!-- If using http requests, then using http needs to be allowed -->
.....................................................................................................
<!-- Since this class has the long connection function, the service with the Engagelab word in the package name may be directly killed during the power-saving optimization by the mobile phone manufacturer -->
<!-- Therefore, developers need to inherit from com.engagelab.app.component.MTCommonService to improve the survival rate of the long connection, so as to achieve the purpose of increasing the message arrival rate -->
<service
android:name="com.engagelab.app.component.UserService"
android:exported="false"
android:process="${ENGAGELAB_PRIVATES_PROCESS}">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_SERVICE" />
</intent-filter>
</service>
<!-- Used to receive the callbacks of Engagelab services, including long connection status/notification switch status/notification message arrival/notification message click/notification message deletion/custom message/vendor token callback -->
<!-- There is no need to configure a sub-process. This callback is in the main process, which is convenient for business operations -->
<receiver
android:name="com.engagelab.app.component.UserReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_RECEIVER" />
</intent-filter>
</receiver>
</application>
</manifest>
This code block in the floating window
5. Initialization
package com.engagelab.app;
import android.app.Application;
import com.engagelab.privates.core.api.Address;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// Must be configured in application.onCreate, do not judge the process, the SDK has its own judgment internally
MTCorePrivatesApi.configDebugMode(this, true);
// Initialize push for push
// MTPushPrivatesApi.init(this);
}
}
package com.engagelab.app;
import android.app.Application;
import com.engagelab.privates.core.api.Address;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// Must be configured in application.onCreate, do not judge the process, the SDK has its own judgment internally
MTCorePrivatesApi.configDebugMode(this, true);
// Initialize push for push
// MTPushPrivatesApi.init(this);
}
}
This code block in the floating window