Engagelab Channel Integration Guide
Last updated:2022-12-13
Engagelab Channel Integration Guide
1. Obtain application information
Create an application in the console. After the application is created, an AppKey is automatically generated to identify the application. For more information, see application Settings .
2. SDK Libs package
Visit Engagelab WebPush and download the lastest version SDK.Import mt-sdk-x.x.x.aar into the libs directory.
3. Configuration of build.gradle
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// app packageName,It needs to be the same as that on the Engagelab application console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// Engagelab appKey,It needs to be the same as that on the Engagelab console, and has a one-to-one relationship with packageName
ENGAGELAB_PRIVATES_APPKEY : "1c4b749a17f6aca33960a560",
// Engagelab appChannel,Used for channel statistics
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelab process,The process where Engagelabsdk works.
ENGAGELAB_PRIVATES_PROCESS: ":remote"
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// app packageName,It needs to be the same as that on the Engagelab application console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// Engagelab appKey,It needs to be the same as that on the Engagelab console, and has a one-to-one relationship with packageName
ENGAGELAB_PRIVATES_APPKEY : "1c4b749a17f6aca33960a560",
// Engagelab appChannel,Used for channel statistics
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelab process,The process where Engagelabsdk works.
ENGAGELAB_PRIVATES_PROCESS: ":remote"
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
This code block in the floating window
4. Create required components
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* Developer inherit the MTCommonService,keep long connections to survive longer
* <p>
* Empty implementation
*/
public class UserService extends MTCommonService {
}
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* Developer inherit the MTCommonService,keep long connections to survive longer
* <p>
* Empty implementation
*/
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;
/**
* The developer inherits MTCommonReceiver and can obtain the method callback of the sdk
* <p>
* All callbacks are in the main thread
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* Application notification switch status callback
*
* @param context is not empty
* @param enable Notify whether the switch is on. True means on, false means off
*/
@Override
public void onNotificationStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onNotificationStatus:" + enable);
Toast.makeText(context.getApplicationContext(), "onNotificationStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isNotificationEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onNotificationStatus(enable);
}
}
/**
* Long tcp connection status callback method
*
* @param context is not empty
* @param enable Whether connected
*/
@Override
public void onConnectStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onConnectState:" + enable);
Toast.makeText(context.getApplicationContext(), "onConnectStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isConnectEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onConnectStatus(enable);
}
// If the long connection succeeds, you can obtain the registrationId
if (enable) {
String registrationId = MTCorePrivatesApi.getRegistrationId(context);
ExampleLogger.i(TAG, "registrationId:" + registrationId);
}
}
/**
* Notification message arrived callback
*
* @param context is not empty
* @param notificationMessage Notification Message
*/
@Override
public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
}
/**
* Notification message click callback method
*
* @param context is not empty
* @param notificationMessage Notification Message
*/
@Override
public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
}
/**
* Notification delete callback method
*
* @param context is not empty
* @param notificationMessage Notification Message
*/
@Override
public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
}
/**
* Custom message callback
*
* @param context is not empty
* @param customMessage Notification Message
*/
@Override
public void onCustomMessage(Context context, CustomMessage customMessage) {
ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
}
/**
* Manufacturer token message callback
*
* @param context is not empty
* @param platformTokenMessage Manufacturer token message
*/
@Override
public void onPlatformToken(Context context, PlatformTokenMessage platformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:" + platformTokenMessage.toString());
}
}
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;
/**
* The developer inherits MTCommonReceiver and can obtain the method callback of the sdk
* <p>
* All callbacks are in the main thread
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* Application notification switch status callback
*
* @param context is not empty
* @param enable Notify whether the switch is on. True means on, false means off
*/
@Override
public void onNotificationStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onNotificationStatus:" + enable);
Toast.makeText(context.getApplicationContext(), "onNotificationStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isNotificationEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onNotificationStatus(enable);
}
}
/**
* Long tcp connection status callback method
*
* @param context is not empty
* @param enable Whether connected
*/
@Override
public void onConnectStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onConnectState:" + enable);
Toast.makeText(context.getApplicationContext(), "onConnectStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isConnectEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onConnectStatus(enable);
}
// If the long connection succeeds, you can obtain the registrationId
if (enable) {
String registrationId = MTCorePrivatesApi.getRegistrationId(context);
ExampleLogger.i(TAG, "registrationId:" + registrationId);
}
}
/**
* Notification message arrived callback
*
* @param context is not empty
* @param notificationMessage Notification Message
*/
@Override
public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
}
/**
* Notification message click callback method
*
* @param context is not empty
* @param notificationMessage Notification Message
*/
@Override
public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
}
/**
* Notification delete callback method
*
* @param context is not empty
* @param notificationMessage Notification Message
*/
@Override
public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
}
/**
* Custom message callback
*
* @param context is not empty
* @param customMessage Notification Message
*/
@Override
public void onCustomMessage(Context context, CustomMessage customMessage) {
ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
}
/**
* Manufacturer token message callback
*
* @param context is not empty
* @param platformTokenMessage Manufacturer token message
*/
@Override
public void onPlatformToken(Context context, PlatformTokenMessage platformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:" + platformTokenMessage.toString());
}
}
This code block in the floating window
5. 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">
<!-- Required, network permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional, notify 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 you use http requests, you need to allow the use of http -->
.....................................................................................................
<!-- Because this class has a long connection function, the service with the package name Engagelab may be directly killed when the mobile phone manufacturer optimizes the power saving -->
<!-- Therefore, developers need to integrate com.engagelab.app.component.MTCommonService to improve the long connection survival rate and 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>
<!-- It is used to receive the callback of Engagelab service, including long connection status, notification switch status, notification message arrival, notification message click, notification message deletion, user-defined message, and manufacturer token callback -->
<!-- There is no need to configure a sub process. This callback is in the main process, facilitating 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">
<!-- Required, network permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional, notify 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 you use http requests, you need to allow the use of http -->
.....................................................................................................
<!-- Because this class has a long connection function, the service with the package name Engagelab may be directly killed when the mobile phone manufacturer optimizes the power saving -->
<!-- Therefore, developers need to integrate com.engagelab.app.component.MTCommonService to improve the long connection survival rate and 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>
<!-- It is used to receive the callback of Engagelab service, including long connection status, notification switch status, notification message arrival, notification message click, notification message deletion, user-defined message, and manufacturer token callback -->
<!-- There is no need to configure a sub process. This callback is in the main process, facilitating 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
6. Environment configuration
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;
/**
* Used to demonstrate ENGAGELAB sdk init configuration
*/
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// It must be configured in application.onCreate. Do not need judge the process. The sdk has internal judgments
MTCorePrivatesApi.configDebugMode(this, true);
// Initialize 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;
/**
* Used to demonstrate ENGAGELAB sdk init configuration
*/
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// It must be configured in application.onCreate. Do not need judge the process. The sdk has internal judgments
MTCorePrivatesApi.configDebugMode(this, true);
// Initialize push
// MTPushPrivatesApi.init(this);
}
}
This code block in the floating window