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

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. // Para el proveedor Meizu: A partir del SDK 5.2.0, integrar Meizu requiere "com.engagelab.plugin:meizu_th_push"; no es necesario antes de 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.
  // Para el proveedor Meizu: A partir del SDK 5.2.0, integrar Meizu requiere "com.engagelab.plugin:meizu_th_push"; no es necesario antes de 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.
}

            
Este bloque de código se muestra en una ventana flotante

Kotlin DSL (build.gradle.kts):

dependencies { // Requerido: paquete principal implementation("com.engagelab:engagelab:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Google implementation("com.engagelab.plugin:google:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Honor implementation("com.engagelab.plugin:honor:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. implementation("com.engagelab.plugin:honor_th_push:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Huawei implementation("com.engagelab.plugin:huawei:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Xiaomi, versión china implementation("com.engagelab.plugin:mi:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Meizu implementation("com.engagelab.plugin:meizu:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Proveedor Meizu: a partir del SDK 5.2.0, integrar Meizu requiere "com.engagelab.plugin:meizu_th_push"; no es necesario antes de 5.2.0. implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Oppo implementation("com.engagelab.plugin:oppo:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: proveedor Vivo implementation("com.engagelab.plugin:vivo:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. // Opcional: función de difusión de voz implementation("com.engagelab.plugin:oth_sound:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo. }
              
              dependencies {
    // Requerido: paquete principal
    implementation("com.engagelab:engagelab:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Google
    implementation("com.engagelab.plugin:google:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Honor
    implementation("com.engagelab.plugin:honor:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    implementation("com.engagelab.plugin:honor_th_push:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Huawei
    implementation("com.engagelab.plugin:huawei:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Xiaomi, versión china
    implementation("com.engagelab.plugin:mi:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Meizu
    implementation("com.engagelab.plugin:meizu:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Proveedor Meizu: a partir del SDK 5.2.0, integrar Meizu requiere "com.engagelab.plugin:meizu_th_push"; no es necesario antes de 5.2.0.
    implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Oppo
    implementation("com.engagelab.plugin:oppo:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: proveedor Vivo
    implementation("com.engagelab.plugin:vivo:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
    // Opcional: función de difusión de voz
    implementation("com.engagelab.plugin:oth_sound:5.3.0") // Aquí usamos la versión 5.3.0 como ejemplo.
}

            
Este bloque de código se muestra en una ventana flotante

2. Configurar build.gradle

Groovy (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

Kotlin:

package com.engagelab.app.component import com.engagelab.privates.common.component.MTCommonService class UserService : MTCommonService() {}
              
              package com.engagelab.app.component
import com.engagelab.privates.common.component.MTCommonService
class UserService : MTCommonService() {}

            
Este bloque de código se muestra en una ventana flotante

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());
    }

}

            
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); // 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);
    }

}

            
Este bloque de código se muestra en una ventana flotante

Kotlin:

package com.engagelab.app import android.app.Application import com.engagelab.privates.core.api.MTCorePrivatesApi import com.engagelab.privates.push.api.MTPushPrivatesApi /** * Se utiliza para demostrar la configuración del SDK ENGAGELAB. */ class MainApplication : Application() { companion object { private const val TAG = "MainApplication" } override fun onCreate() { super.onCreate() // Debe configurarse en application.onCreate; no comprobar el proceso, el SDK lo comprueba internamente MTCorePrivatesApi.configDebugMode(this, true) // Inicializar 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

/**
 * Se utiliza para demostrar la configuración del SDK ENGAGELAB.
 */
class MainApplication : Application() {

    companion object {
        private const val TAG = "MainApplication"
    }

    override fun onCreate() {
        super.onCreate()

        // Debe configurarse en application.onCreate; no comprobar el proceso, el SDK lo comprueba internamente
        MTCorePrivatesApi.configDebugMode(this, true)

        // Inicializar 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. * * 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();
        }
    }
        
}

            
Este bloque de código se muestra en una ventana flotante

Kotlin:

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 /** * Se utiliza para demostrar el salto a una actividad al hacer clic en una notificación. * * No es necesario llamar a MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String); el SDK lo gestiona internamente. */ 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 } // A partir de la versión 3.4.0 ya no se usa el objeto; se usan datos JSON 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.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

/**
 * Se utiliza para demostrar el salto a una actividad al hacer clic en una notificación.
 *
 * No es necesario llamar a MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String); el SDK lo gestiona internamente.
 */
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
            }
            // A partir de la versión 3.4.0 ya no se usa el objeto; se usan datos JSON
            val notificationMessage = intent.getStringExtra("message_json")
            if (notificationMessage == null) {
                return
            }
            ExampleLogger.d(TAG, "notificationMessage:$notificationMessage")
            tvMessage.text = notificationMessage
        } 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)

Icon Solid Transparent White Qiyu
Contacto