Engagelab Channel Integration Guide
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 .
Importing Libraries
- Manual method
Import the mt-sdk-x.x.x.aar from the libs folder into the libs directory.
Import th-xxx-x.x.x.aar under the libs package into the libs directory
Import the mt-sdk-x.x.x.aar from the libs folder into the libs directory.
Import th-xxx-x.x.x.aar under the libs package into the libs directory
This code block in the floating window
- Automatic method
Groovy (build.gradle):
dependencies {
// Required: Main package
implementation 'com.engagelab:engagelab:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Google vendor
implementation 'com.engagelab.plugin:google:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Honor vendor
implementation 'com.engagelab.plugin:honor:5.3.0' // Here, we use version 5.3.0 as an example.
implementation 'com.engagelab.plugin:honor_th_push:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Huawei vendor
implementation 'com.engagelab.plugin:huawei:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Xiaomi vendor, Chinese version
implementation 'com.engagelab.plugin:mi:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Meizu vendor
implementation 'com.engagelab.plugin:meizu:5.3.0' // Here, we use version 5.3.0 as an example.
// For Meizu vendor: Starting from SDK 5.2.0, integrating Meizu requires "com.engagelab.plugin:meizu_th_push"; not required before 5.2.0.
implementation 'com.engagelab.plugin:meizu_th_push:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Oppo vendor
implementation 'com.engagelab.plugin:oppo:5.3.0' // Here, we use version 5.3.0 as an example.
implementation 'com.engagelab.plugin:oppo_th_push:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Vivo vendor
implementation 'com.engagelab.plugin:vivo:5.3.0' // Here, we use version 5.3.0 as an example.
//Optional: sound voice broadcast function
implementation 'com.engagelab.plugin:oth_sound:5.3.0' // Take version 5.3.0 as an example here.
}
dependencies {
// Required: Main package
implementation 'com.engagelab:engagelab:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Google vendor
implementation 'com.engagelab.plugin:google:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Honor vendor
implementation 'com.engagelab.plugin:honor:5.3.0' // Here, we use version 5.3.0 as an example.
implementation 'com.engagelab.plugin:honor_th_push:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Huawei vendor
implementation 'com.engagelab.plugin:huawei:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Xiaomi vendor, Chinese version
implementation 'com.engagelab.plugin:mi:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Meizu vendor
implementation 'com.engagelab.plugin:meizu:5.3.0' // Here, we use version 5.3.0 as an example.
// For Meizu vendor: Starting from SDK 5.2.0, integrating Meizu requires "com.engagelab.plugin:meizu_th_push"; not required before 5.2.0.
implementation 'com.engagelab.plugin:meizu_th_push:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Oppo vendor
implementation 'com.engagelab.plugin:oppo:5.3.0' // Here, we use version 5.3.0 as an example.
implementation 'com.engagelab.plugin:oppo_th_push:5.3.0' // Here, we use version 5.3.0 as an example.
// Optional: Vivo vendor
implementation 'com.engagelab.plugin:vivo:5.3.0' // Here, we use version 5.3.0 as an example.
//Optional: sound voice broadcast function
implementation 'com.engagelab.plugin:oth_sound:5.3.0' // Take version 5.3.0 as an example here.
}
This code block in the floating window
Kotlin DSL (build.gradle.kts):
dependencies {
// Required: Main package
implementation("com.engagelab:engagelab:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Google vendor
implementation("com.engagelab.plugin:google:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Honor vendor
implementation("com.engagelab.plugin:honor:5.3.0") // Here, we use version 5.3.0 as an example.
implementation("com.engagelab.plugin:honor_th_push:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Huawei vendor
implementation("com.engagelab.plugin:huawei:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Xiaomi vendor, Chinese version
implementation("com.engagelab.plugin:mi:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Meizu vendor
implementation("com.engagelab.plugin:meizu:5.3.0") // Here, we use version 5.3.0 as an example.
// For Meizu vendor: Starting from SDK 5.2.0, integrating Meizu requires "com.engagelab.plugin:meizu_th_push"; not required before 5.2.0.
implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Oppo vendor
implementation("com.engagelab.plugin:oppo:5.3.0") // Here, we use version 5.3.0 as an example.
implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Vivo vendor
implementation("com.engagelab.plugin:vivo:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: sound voice broadcast function
implementation("com.engagelab.plugin:oth_sound:5.3.0") // Here, we use version 5.3.0 as an example.
}
dependencies {
// Required: Main package
implementation("com.engagelab:engagelab:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Google vendor
implementation("com.engagelab.plugin:google:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Honor vendor
implementation("com.engagelab.plugin:honor:5.3.0") // Here, we use version 5.3.0 as an example.
implementation("com.engagelab.plugin:honor_th_push:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Huawei vendor
implementation("com.engagelab.plugin:huawei:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Xiaomi vendor, Chinese version
implementation("com.engagelab.plugin:mi:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Meizu vendor
implementation("com.engagelab.plugin:meizu:5.3.0") // Here, we use version 5.3.0 as an example.
// For Meizu vendor: Starting from SDK 5.2.0, integrating Meizu requires "com.engagelab.plugin:meizu_th_push"; not required before 5.2.0.
implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Oppo vendor
implementation("com.engagelab.plugin:oppo:5.3.0") // Here, we use version 5.3.0 as an example.
implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: Vivo vendor
implementation("com.engagelab.plugin:vivo:5.3.0") // Here, we use version 5.3.0 as an example.
// Optional: sound voice broadcast function
implementation("com.engagelab.plugin:oth_sound:5.3.0") // Here, we use version 5.3.0 as an example.
}
This code block in the floating window
2. Configure build.gradle
Groovy (build.gradle):
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// App package name, should be the same as on the console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// AppKey, should be the same as on the console; one-to-one relationship with packageName
ENGAGELAB_PRIVATES_APPKEY : "YourAppKey",
// Engagelab appChannel, used for channel statistics
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelab process, the process where Engagelab SDK works; note: starts with
ENGAGELAB_PRIVATES_PROCESS: ":remote",
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// App package name, should be the same as on the console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// AppKey, should be the same as on the console; one-to-one relationship with packageName
ENGAGELAB_PRIVATES_APPKEY : "YourAppKey",
// Engagelab appChannel, used for channel statistics
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelab process, the process where Engagelab SDK works; note: starts with
ENGAGELAB_PRIVATES_PROCESS: ":remote",
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
This code block in the floating window
Kotlin DSL (build.gradle.kts):
plugins {
alias(libs.plugins.android.application)
}
android {
// ...
defaultConfig {
// App package name, should be the same as on the console
applicationId = "com.engagelab.app"
// ...
manifestPlaceholders.putAll(mapOf(
// AppKey, should be the same as on the console; one-to-one relationship with packageName
"ENGAGELAB_PRIVATES_APPKEY" to "YourAppKey",
// Engagelab appChannel, used for channel statistics
"ENGAGELAB_PRIVATES_CHANNEL" to "developer",
// Engagelab process, the process where Engagelab SDK works; note: starts with :
"ENGAGELAB_PRIVATES_PROCESS" to ":remote"
))
}
}
dependencies {
implementation(fileTree(mapOf("include" to listOf("*.jar", "*.aar"), "dir" to "libs")))
}
plugins {
alias(libs.plugins.android.application)
}
android {
// ...
defaultConfig {
// App package name, should be the same as on the console
applicationId = "com.engagelab.app"
// ...
manifestPlaceholders.putAll(mapOf(
// AppKey, should be the same as on the console; one-to-one relationship with packageName
"ENGAGELAB_PRIVATES_APPKEY" to "YourAppKey",
// Engagelab appChannel, used for channel statistics
"ENGAGELAB_PRIVATES_CHANNEL" to "developer",
// Engagelab process, the process where Engagelab SDK works; note: starts with :
"ENGAGELAB_PRIVATES_PROCESS" to ":remote"
))
}
}
dependencies {
implementation(fileTree(mapOf("include" to listOf("*.jar", "*.aar"), "dir" to "libs")))
}
This code block in the floating window
Create required components
Java:
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* Developers can extend MTCommonService to prolong the longevity of the long connection.
*
* Empty implementation is sufficient.
*/
public class UserService extends MTCommonService {
}
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* Developers can extend MTCommonService to prolong the longevity of the long connection.
*
* Empty implementation is sufficient.
*/
public class UserService extends MTCommonService {
}
This code block in the floating window
Kotlin:
package com.engagelab.app.component
import com.engagelab.privates.common.component.MTCommonService
/**
* Developers can extend MTCommonService to prolong the longevity of the long connection.
*
* Empty implementation is sufficient.
*/
class UserService : MTCommonService() {
}
package com.engagelab.app.component
import com.engagelab.privates.common.component.MTCommonService
/**
* Developers can extend MTCommonService to prolong the longevity of the long connection.
*
* Empty implementation is sufficient.
*/
class UserService : MTCommonService() {
}
This code block in the floating window
Java:
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 can extend MTCommonReceiver to receive method callbacks from the SDK.
*
* All callbacks are in the main thread.
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* Callback for the application notification switch status.
*
* @param context Not null
* @param enable Notification switch status, true for on, false for 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 connection status callback.
*
* @param context Not null
* @param enable Whether the connection is established
*/
@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);
}
// Get the registrationId when the long connection is established
if (enable) {
String registrationId = MTCorePrivatesApi.getRegistrationId(context);
ExampleLogger.i(TAG, "registrationId:" + registrationId);
}
}
/**
* Callback for notification message arrival.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
}
/**
* Callback for notification messages not displayed in the foreground.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString());
}
/**
* Callback for notification message click.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
}
/**
* Callback for notification message deletion.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
}
/**
* Custom message callback.
*
* @param context Not null
* @param customMessage Custom message
*/
@Override
public void onCustomMessage(Context context, CustomMessage customMessage) {
ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
}
/**
* Vendor token message callback.
*
* @param context Not null
* @param platformTokenMessage Vendor 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;
/**
* Developers can extend MTCommonReceiver to receive method callbacks from the SDK.
*
* All callbacks are in the main thread.
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* Callback for the application notification switch status.
*
* @param context Not null
* @param enable Notification switch status, true for on, false for 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 connection status callback.
*
* @param context Not null
* @param enable Whether the connection is established
*/
@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);
}
// Get the registrationId when the long connection is established
if (enable) {
String registrationId = MTCorePrivatesApi.getRegistrationId(context);
ExampleLogger.i(TAG, "registrationId:" + registrationId);
}
}
/**
* Callback for notification message arrival.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
}
/**
* Callback for notification messages not displayed in the foreground.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString());
}
/**
* Callback for notification message click.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
}
/**
* Callback for notification message deletion.
*
* @param context Not null
* @param notificationMessage Notification message
*/
@Override
public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
}
/**
* Custom message callback.
*
* @param context Not null
* @param customMessage Custom message
*/
@Override
public void onCustomMessage(Context context, CustomMessage customMessage) {
ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
}
/**
* Vendor token message callback.
*
* @param context Not null
* @param platformTokenMessage Vendor token message
*/
@Override
public void onPlatformToken(Context context, PlatformTokenMessage platformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:" + platformTokenMessage.toString());
}
}
This code block in the floating window
Kotlin:
package com.engagelab.app.component
import android.content.Context
import android.widget.Toast
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.push.api.CustomMessage
import com.engagelab.privates.push.api.NotificationMessage
import com.engagelab.privates.push.api.PlatformTokenMessage
/**
* Developers can extend MTCommonReceiver to receive method callbacks from the SDK.
* All callbacks are in the main thread.
*/
class UserReceiver : MTCommonReceiver() {
companion object {
private const val TAG = "UserReceiver"
}
/**
* Application notification switch status callback.
*
* @param context non-null
* @param enable whether notification is on, true=on, false=off
*/
override fun onNotificationStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onNotificationStatus:$enable")
Toast.makeText(context.applicationContext, "onNotificationStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isNotificationEnable = enable
StatusObserver.getInstance().listener?.onNotificationStatus(enable)
}
/**
* Long connection status callback.
*
* @param context non-null
* @param enable whether connected
*/
override fun onConnectStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onConnectState:$enable")
Toast.makeText(context.applicationContext, "onConnectStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isConnectEnable = enable
StatusObserver.getInstance().listener?.onConnectStatus(enable)
// When long connection succeeds, registrationId can be obtained
if (enable) {
val registrationId = MTCorePrivatesApi.getRegistrationId(context)
ExampleLogger.i(TAG, "registrationId:$registrationId")
}
}
/**
* Notification message arrived callback.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}")
}
/**
* Notification not shown when app is in foreground.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}")
}
/**
* Notification message click callback.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}")
}
/**
* Notification message deleted callback.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}")
}
/**
* Custom message callback.
*
* @param context non-null
* @param customMessage custom message
*/
override fun onCustomMessage(context: Context, customMessage: CustomMessage) {
ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}")
}
/**
* Vendor token message callback.
*
* @param context non-null
* @param platformTokenMessage vendor token message
*/
override fun 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 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.push.api.CustomMessage
import com.engagelab.privates.push.api.NotificationMessage
import com.engagelab.privates.push.api.PlatformTokenMessage
/**
* Developers can extend MTCommonReceiver to receive method callbacks from the SDK.
* All callbacks are in the main thread.
*/
class UserReceiver : MTCommonReceiver() {
companion object {
private const val TAG = "UserReceiver"
}
/**
* Application notification switch status callback.
*
* @param context non-null
* @param enable whether notification is on, true=on, false=off
*/
override fun onNotificationStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onNotificationStatus:$enable")
Toast.makeText(context.applicationContext, "onNotificationStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isNotificationEnable = enable
StatusObserver.getInstance().listener?.onNotificationStatus(enable)
}
/**
* Long connection status callback.
*
* @param context non-null
* @param enable whether connected
*/
override fun onConnectStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onConnectState:$enable")
Toast.makeText(context.applicationContext, "onConnectStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isConnectEnable = enable
StatusObserver.getInstance().listener?.onConnectStatus(enable)
// When long connection succeeds, registrationId can be obtained
if (enable) {
val registrationId = MTCorePrivatesApi.getRegistrationId(context)
ExampleLogger.i(TAG, "registrationId:$registrationId")
}
}
/**
* Notification message arrived callback.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}")
}
/**
* Notification not shown when app is in foreground.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}")
}
/**
* Notification message click callback.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}")
}
/**
* Notification message deleted callback.
*
* @param context non-null
* @param notificationMessage notification message
*/
override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}")
}
/**
* Custom message callback.
*
* @param context non-null
* @param customMessage custom message
*/
override fun onCustomMessage(context: Context, customMessage: CustomMessage) {
ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}")
}
/**
* Vendor token message callback.
*
* @param context non-null
* @param platformTokenMessage vendor token message
*/
override fun onPlatformToken(context: Context, platformTokenMessage: PlatformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:${platformTokenMessage.toString()}")
}
}
This code block in the floating window
4. Configure AndroidManifest.xml
<?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: Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional: Vibration for notifications -->
<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, allow HTTP -->
.....................................................................................................
<!-- Due to the long connection feature of this class, the power-saving optimization by the manufacturer may directly kill the service with a package name containing "Engagelab" in the name. -->
<!-- Therefore, developers need to extend com.engagelab.app.component.MTCommonService to improve the long connection survival rate and increase 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 Engagelab business callbacks, including long connection status/notification switch status/notification message arrival/notification message click/notification message deletion/custom message/vendor token callback -->
<!-- No need to configure sub-processes; this callback is in the main process for ease of 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: Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional: Vibration for notifications -->
<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, allow HTTP -->
.....................................................................................................
<!-- Due to the long connection feature of this class, the power-saving optimization by the manufacturer may directly kill the service with a package name containing "Engagelab" in the name. -->
<!-- Therefore, developers need to extend com.engagelab.app.component.MTCommonService to improve the long connection survival rate and increase 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 Engagelab business callbacks, including long connection status/notification switch status/notification message arrival/notification message click/notification message deletion/custom message/vendor token callback -->
<!-- No need to configure sub-processes; this callback is in the main process for ease of 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. Environment Configuration
Java:
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 the configuration of the ENGAGELAB-sdk.
*/
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// Configuration must be done in application.onCreate, no need to check processes, the SDK has an internal check.
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 the configuration of the ENGAGELAB-sdk.
*/
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// Configuration must be done in application.onCreate, no need to check processes, the SDK has an internal check.
MTCorePrivatesApi.configDebugMode(this, true);
// Initialize push
MTPushPrivatesApi.init(this);
}
}
This code block in the floating window
Kotlin:
package com.engagelab.app
import android.app.Application
import com.engagelab.privates.core.api.MTCorePrivatesApi
import com.engagelab.privates.push.api.MTPushPrivatesApi
/**
* Used to demonstrate the configuration of the ENGAGELAB-sdk.
*/
class MainApplication : Application() {
companion object {
private const val TAG = "MainApplication"
}
override fun onCreate() {
super.onCreate()
// Must be configured in application.onCreate; do not check process—the SDK checks internally
MTCorePrivatesApi.configDebugMode(this, true)
// Initialize push
MTPushPrivatesApi.init(this)
}
}
package com.engagelab.app
import android.app.Application
import com.engagelab.privates.core.api.MTCorePrivatesApi
import com.engagelab.privates.push.api.MTPushPrivatesApi
/**
* Used to demonstrate the configuration of the ENGAGELAB-sdk.
*/
class MainApplication : Application() {
companion object {
private const val TAG = "MainApplication"
}
override fun onCreate() {
super.onCreate()
// Must be configured in application.onCreate; do not check process—the SDK checks internally
MTCorePrivatesApi.configDebugMode(this, true)
// Initialize push
MTPushPrivatesApi.init(this)
}
}
This code block in the floating window
6. Create a Notification Click Jump Component
Java:
package com.engagelab.app.component;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.engagelab.app.R;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.constants.MTPushConstants;
/**
* Used to demonstrate clicking on a notification to jump to an activity.
*
* No need to call MTPushPrivatesApi.reportNotificationOpened(Context, String, byte, String); the SDK handles it internally.
*/
public class UserActivity400 extends Activity {
private static final String TAG = "UserActivity400";
private TextView tvMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
tvMessage = findViewById(R.id.tv_message);
onIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
onIntent(intent);
}
private void onIntent(Intent intent) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show();
if (intent == null) {
return;
}
// Starting from version 3.4.0, objects are no longer used; JSON data is used instead
String notificationMessage = intent.getStringExtra("message_json");
if (notificationMessage == null) {
return;
}
ExampleLogger.d(TAG, "notificationMessage:" + notificationMessage.toString());
tvMessage.setText(notificationMessage.toString());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
package com.engagelab.app.component;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.engagelab.app.R;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.constants.MTPushConstants;
/**
* Used to demonstrate clicking on a notification to jump to an activity.
*
* No need to call MTPushPrivatesApi.reportNotificationOpened(Context, String, byte, String); the SDK handles it internally.
*/
public class UserActivity400 extends Activity {
private static final String TAG = "UserActivity400";
private TextView tvMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
tvMessage = findViewById(R.id.tv_message);
onIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
onIntent(intent);
}
private void onIntent(Intent intent) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show();
if (intent == null) {
return;
}
// Starting from version 3.4.0, objects are no longer used; JSON data is used instead
String notificationMessage = intent.getStringExtra("message_json");
if (notificationMessage == null) {
return;
}
ExampleLogger.d(TAG, "notificationMessage:" + notificationMessage.toString());
tvMessage.setText(notificationMessage.toString());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
This code block in the floating window
Kotlin:
package com.engagelab.app.component
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.engagelab.app.R
import com.engagelab.app.log.ExampleLogger
/**
* Used to demonstrate activity jump after clicking a notification.
*
* No need to call MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String); the SDK handles it internally.
*/
class UserActivity400 : Activity() {
companion object {
private const val TAG = "UserActivity400"
}
private lateinit var tvMessage: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_intent)
tvMessage = findViewById(R.id.tv_message)
onIntent(intent)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
onIntent(intent)
}
private fun onIntent(intent: Intent?) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show()
if (intent == null) {
return
}
// As of version 3.4.0, object is no longer used; JSON data is used instead
val notificationMessage = intent.getStringExtra("message_json")
if (notificationMessage == null) {
return
}
ExampleLogger.d(TAG, "notificationMessage:$notificationMessage")
tvMessage.text = notificationMessage
} catch (throwable: Throwable) {
throwable.printStackTrace()
}
}
}
package com.engagelab.app.component
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.engagelab.app.R
import com.engagelab.app.log.ExampleLogger
/**
* Used to demonstrate activity jump after clicking a notification.
*
* No need to call MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String); the SDK handles it internally.
*/
class UserActivity400 : Activity() {
companion object {
private const val TAG = "UserActivity400"
}
private lateinit var tvMessage: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_intent)
tvMessage = findViewById(R.id.tv_message)
onIntent(intent)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
onIntent(intent)
}
private fun onIntent(intent: Intent?) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show()
if (intent == null) {
return
}
// As of version 3.4.0, object is no longer used; JSON data is used instead
val notificationMessage = intent.getStringExtra("message_json")
if (notificationMessage == null) {
return
}
ExampleLogger.d(TAG, "notificationMessage:$notificationMessage")
tvMessage.text = notificationMessage
} catch (throwable: Throwable) {
throwable.printStackTrace()
}
}
}
This code block in the floating window
7. Configure the AndroidManifest.xml for Click Jump
<?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: Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional: Vibration for notifications -->
<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, allow HTTP -->
..............................................................
<!-- Used to demonstrate notification click jump -->
<activity
android:name="com.engagelab.app.component.UserActivity400"
android:exported="false"
android:launchMode="singleTask" />
<!-- Used to demonstrate notification click jump with deep links -->
<!-- <activity-->
<!-- android:name="com.engagelab.app.component.UserActivity400"-->
<!-- android:exported="false" >-->
<!-- <intent-filter>-->
<!-- <data android:scheme="YourScheme"/>-->
<!-- <data android:host="YourHost"/>-->
<!-- <action android:name="android.intent.action.VIEW" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="android.intent.category.BROWSABLE" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<!-- White-listed local transfer verification: Starting from MTPush 4.2.3, after configuring ENGAGELAB_PRIVATES_TRANSFER, the SDK will perform local verification. If local verification is enabled, please configure the target Activity to be jumped to here. If there are multiple target Activities, please separate them with /. -->
<meta-data
android:name="ENGAGELAB_PRIVATES_TRANSFER"
android:value="com.engagelab.app.component.UserActivity400" />
<!-- Google push need: Remove if Google channel is not needed -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
<!-- Huawei push need: Remove if Huawei channel is not needed -->
<meta-data
android:name="com.huawei.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
</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: Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Optional: Vibration for notifications -->
<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, allow HTTP -->
..............................................................
<!-- Used to demonstrate notification click jump -->
<activity
android:name="com.engagelab.app.component.UserActivity400"
android:exported="false"
android:launchMode="singleTask" />
<!-- Used to demonstrate notification click jump with deep links -->
<!-- <activity-->
<!-- android:name="com.engagelab.app.component.UserActivity400"-->
<!-- android:exported="false" >-->
<!-- <intent-filter>-->
<!-- <data android:scheme="YourScheme"/>-->
<!-- <data android:host="YourHost"/>-->
<!-- <action android:name="android.intent.action.VIEW" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="android.intent.category.BROWSABLE" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<!-- White-listed local transfer verification: Starting from MTPush 4.2.3, after configuring ENGAGELAB_PRIVATES_TRANSFER, the SDK will perform local verification. If local verification is enabled, please configure the target Activity to be jumped to here. If there are multiple target Activities, please separate them with /. -->
<meta-data
android:name="ENGAGELAB_PRIVATES_TRANSFER"
android:value="com.engagelab.app.component.UserActivity400" />
<!-- Google push need: Remove if Google channel is not needed -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
<!-- Huawei push need: Remove if Huawei channel is not needed -->
<meta-data
android:name="com.huawei.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
</application>
</manifest>
This code block in the floating window
