Guía de integración del canal Engagelab
Obtener información de la aplicación
Crear una aplicación en la consola. Una vez creada la aplicación, se genera automáticamente un AppKey para identificarla. Para más información, consulte Configuración de la aplicación.
Importación de bibliotecas
- Método manual
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
Este bloque de código se muestra en una ventana flotante
- Método automático
dependencies {
// Required: Main package
implementation 'com.engagelab:engagelab:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Google vendor
implementation 'com.engagelab.plugin:google:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Honor vendor
implementation 'com.engagelab.plugin:honor:4.3.9' // Here, we use version 4.3.9 as an example.
implementation 'com.engagelab.plugin:honor_th_push:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Huawei vendor
implementation 'com.engagelab.plugin:huawei:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Xiaomi vendor, Chinese version
implementation 'com.engagelab.plugin:mi:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Meizu vendor
implementation 'com.engagelab.plugin:meizu:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Oppo vendor
implementation 'com.engagelab.plugin:oppo:4.3.9' // Here, we use version 4.3.9 as an example.
implementation 'com.engagelab.plugin:oppo_th_push:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Vivo vendor
implementation 'com.engagelab.plugin:vivo:4.3.9' // Here, we use version 4.3.9 as an example.
//Optional: sound voice broadcast function
implementation 'com.engagelab.plugin:oth_sound:4.3.9' // Take version 4.3.9 as an example here.
}
dependencies {
// Required: Main package
implementation 'com.engagelab:engagelab:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Google vendor
implementation 'com.engagelab.plugin:google:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Honor vendor
implementation 'com.engagelab.plugin:honor:4.3.9' // Here, we use version 4.3.9 as an example.
implementation 'com.engagelab.plugin:honor_th_push:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Huawei vendor
implementation 'com.engagelab.plugin:huawei:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Xiaomi vendor, Chinese version
implementation 'com.engagelab.plugin:mi:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Meizu vendor
implementation 'com.engagelab.plugin:meizu:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Oppo vendor
implementation 'com.engagelab.plugin:oppo:4.3.9' // Here, we use version 4.3.9 as an example.
implementation 'com.engagelab.plugin:oppo_th_push:4.3.9' // Here, we use version 4.3.9 as an example.
// Optional: Vivo vendor
implementation 'com.engagelab.plugin:vivo:4.3.9' // Here, we use version 4.3.9 as an example.
//Optional: sound voice broadcast function
implementation 'com.engagelab.plugin:oth_sound:4.3.9' // Take version 4.3.9 as an example here.
}
Este bloque de código se muestra en una ventana flotante
2. Configurar build.gradle
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// App package name; must be the same as in the console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// AppKey; must be the same as in 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 in which the Engagelab SDK runs; 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; must be the same as in the console
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// AppKey; must be the same as in 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 in which the Engagelab SDK runs; note: starts with
ENGAGELAB_PRIVATES_PROCESS: ":remote",
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
Este bloque de código se muestra en una ventana flotante
3. Crear componentes obligatorios
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 {
}
Este bloque de código se muestra en una ventana flotante
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());
}
}
Este bloque de código se muestra en una ventana flotante
4. Configurar AndroidManifest.xml
(sin cambios)
5. Configurar el entorno
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);
// For versions before tag: V3.5.4-newportal-20210823-gamma.57, this method must be called by the frontend developers; otherwise, there will be issues with notification click jump.
// MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext());
// 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);
// For versions before tag: V3.5.4-newportal-20210823-gamma.57, this method must be called by the frontend developers; otherwise, there will be issues with notification click jump.
// MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext());
// Initialize push
// MTPushPrivatesApi.init(this);
}
}
Este bloque de código se muestra en una ventana flotante
6. Crear un componente de redirección por clic en una notificación
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.
*
* Make sure that MTPushPrivatesApi.configOldPushVersion(Context) is not called, otherwise the notification click jump will not go to this page.
* <p>
* 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.
*
* Make sure that MTPushPrivatesApi.configOldPushVersion(Context) is not called, otherwise the notification click jump will not go to this page.
* <p>
* 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();
}
}
}
Este bloque de código se muestra en una ventana flotante
7. Configurar AndroidManifest.xml para la redirección por clic
(sin cambios en el contenido del bloque de código)
