Logo Site EngageLab Mark Colored Transparent文件
搜尋

Engagelab通道集成文檔

獲取應用信息

在控制台上創建應用,創建成功後自動生成 AppKey 用以標識該應用,詳情參考 應用設置文檔

1.libs導包

  • 手動方式
    將libs套件下面的mt-sdk-x.x.x.aar導入libs目錄 將libs套件下面的th-xxx-x.x.x.aar導入libs目錄
                  
                  將libs套件下面的mt-sdk-x.x.x.aar導入libs目錄
    將libs套件下面的th-xxx-x.x.x.aar導入libs目錄
    
                
    此代碼塊在浮窗中顯示
  • 自動方式

Groovy (build.gradle):

dependencies { //必須 主包 implementation 'com.engagelab:engagelab:5.3.0' // 此處以5.3.0 版本為例。 //可選,google廠商 implementation 'com.engagelab.plugin:google:5.3.0' // 此處以5.3.0 版本為例。 //可選,honor廠商 implementation 'com.engagelab.plugin:honor:5.3.0' // 此處以5.3.0 版本為例。 implementation 'com.engagelab.plugin:honor_th_push:5.3.0' // 此處以5.3.0 版本為例。 //可選,huawei廠商 implementation 'com.engagelab.plugin:huawei:5.3.0' // 此處以5.3.0 版本為例。 //可選,mi廠商,國內版 implementation 'com.engagelab.plugin:mi:5.3.0' // 此處以5.3.0 版本為例。 //可選,meizu廠商 implementation 'com.engagelab.plugin:meizu:5.3.0' // 此處以5.3.0 版本為例。 // meizu廠商,從SDK5.2.0版本開始,集成魅族廠商需要集成"com.engagelab.plugin:meizu_th_push", 5.2.0版本之前不需要。 implementation 'com.engagelab.plugin:meizu_th_push:5.3.0' // 此處以5.3.0 版本為例。 //可選,oppo廠商 implementation 'com.engagelab.plugin:oppo:5.3.0' // 此處以5.3.0 版本為例。 implementation 'com.engagelab.plugin:oppo_th_push:5.3.0' // 此處以5.3.0 版本為例。 //可選,vivo廠商 implementation 'com.engagelab.plugin:vivo:5.3.0' // 此處以5.3.0 版本為例。 //可選,sound語音播報功能 implementation 'com.engagelab.plugin:oth_sound:5.3.0' // 此處以5.3.0 版本為例。 }
              
              dependencies {
  //必須 主包
  implementation 'com.engagelab:engagelab:5.3.0' // 此處以5.3.0 版本為例。
      //可選,google廠商
      implementation 'com.engagelab.plugin:google:5.3.0' // 此處以5.3.0 版本為例。
      //可選,honor廠商
      implementation 'com.engagelab.plugin:honor:5.3.0' // 此處以5.3.0 版本為例。
      implementation 'com.engagelab.plugin:honor_th_push:5.3.0' // 此處以5.3.0 版本為例。
      //可選,huawei廠商
      implementation 'com.engagelab.plugin:huawei:5.3.0' // 此處以5.3.0 版本為例。
      //可選,mi廠商,國內版
      implementation 'com.engagelab.plugin:mi:5.3.0' // 此處以5.3.0 版本為例。
      //可選,meizu廠商
      implementation 'com.engagelab.plugin:meizu:5.3.0' // 此處以5.3.0 版本為例。
      // meizu廠商,從SDK5.2.0版本開始,集成魅族廠商需要集成"com.engagelab.plugin:meizu_th_push", 5.2.0版本之前不需要。
      implementation 'com.engagelab.plugin:meizu_th_push:5.3.0' // 此處以5.3.0 版本為例。
      //可選,oppo廠商
      implementation 'com.engagelab.plugin:oppo:5.3.0' // 此處以5.3.0 版本為例。
      implementation 'com.engagelab.plugin:oppo_th_push:5.3.0' // 此處以5.3.0 版本為例。
      //可選,vivo廠商
      implementation 'com.engagelab.plugin:vivo:5.3.0' // 此處以5.3.0 版本為例。
      //可選,sound語音播報功能
  implementation 'com.engagelab.plugin:oth_sound:5.3.0' // 此處以5.3.0 版本為例。
}

            
此代碼塊在浮窗中顯示

Kotlin DSL (build.gradle.kts):

dependencies { // 必須 主包 implementation("com.engagelab:engagelab:5.3.0") // 此處以5.3.0 版本為例。 // 可選,google廠商 implementation("com.engagelab.plugin:google:5.3.0") // 此處以5.3.0 版本為例。 // 可選,honor廠商 implementation("com.engagelab.plugin:honor:5.3.0") // 此處以5.3.0 版本為例。 implementation("com.engagelab.plugin:honor_th_push:5.3.0") // 此處以5.3.0 版本為例。 // 可選,huawei廠商 implementation("com.engagelab.plugin:huawei:5.3.0") // 此處以5.3.0 版本為例。 // 可選,mi廠商,國內版 implementation("com.engagelab.plugin:mi:5.3.0") // 此處以5.3.0 版本為例。 // 可選,meizu廠商 implementation("com.engagelab.plugin:meizu:5.3.0") // 此處以5.3.0 版本為例。 // meizu廠商,從SDK5.2.0版本開始,集成魅族廠商需要集成"com.engagelab.plugin:meizu_th_push", 5.2.0版本之前不需要。 implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // 此處以5.3.0 版本為例。 // 可選,oppo廠商 implementation("com.engagelab.plugin:oppo:5.3.0") // 此處以5.3.0 版本為例。 implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // 此處以5.3.0 版本為例。 // 可選,vivo廠商 implementation("com.engagelab.plugin:vivo:5.3.0") // 此處以5.3.0 版本為例。 // 可選,sound語音播報功能 implementation("com.engagelab.plugin:oth_sound:5.3.0") // 此處以5.3.0 版本為例。 }
              
              dependencies {
    // 必須 主包
    implementation("com.engagelab:engagelab:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,google廠商
    implementation("com.engagelab.plugin:google:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,honor廠商
    implementation("com.engagelab.plugin:honor:5.3.0") // 此處以5.3.0 版本為例。
    implementation("com.engagelab.plugin:honor_th_push:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,huawei廠商
    implementation("com.engagelab.plugin:huawei:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,mi廠商,國內版
    implementation("com.engagelab.plugin:mi:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,meizu廠商
    implementation("com.engagelab.plugin:meizu:5.3.0") // 此處以5.3.0 版本為例。
    // meizu廠商,從SDK5.2.0版本開始,集成魅族廠商需要集成"com.engagelab.plugin:meizu_th_push", 5.2.0版本之前不需要。
    implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,oppo廠商
    implementation("com.engagelab.plugin:oppo:5.3.0") // 此處以5.3.0 版本為例。
    implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,vivo廠商
    implementation("com.engagelab.plugin:vivo:5.3.0") // 此處以5.3.0 版本為例。
    // 可選,sound語音播報功能
    implementation("com.engagelab.plugin:oth_sound:5.3.0") // 此處以5.3.0 版本為例。
}

            
此代碼塊在浮窗中顯示

2.build.gradle配置

Groovy (build.gradle):

plugins { id 'com.android.application' } android { ... defaultConfig { // app packageName,需要與控制台上的一樣 applicationId "com.engagelab.app" ... manifestPlaceholders = [ //appKey,需要與控制台上的一樣,與packageName是一對一關係 ENGAGELAB_PRIVATES_APPKEY : "您的appkey", // Engagelab appChannel,用於渠道統計 ENGAGELAB_PRIVATES_CHANNEL: "developer", // Engagelab process,Engagelabsdk工作所在的進程,注意:開頭 ENGAGELAB_PRIVATES_PROCESS: ":remote", ] } } dependencies { implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') }
              
              plugins {
    id 'com.android.application'
}

android {
    ...

    defaultConfig {
        // app packageName,需要與控制台上的一樣
        applicationId "com.engagelab.app"
        ...
                
        manifestPlaceholders = [
                //appKey,需要與控制台上的一樣,與packageName是一對一關係
                ENGAGELAB_PRIVATES_APPKEY : "您的appkey",
                // Engagelab appChannel,用於渠道統計
                ENGAGELAB_PRIVATES_CHANNEL: "developer",
                // Engagelab process,Engagelabsdk工作所在的進程,注意:開頭
                ENGAGELAB_PRIVATES_PROCESS: ":remote",
                
        ]
    }
}

dependencies {
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}

            
此代碼塊在浮窗中顯示

Kotlin DSL (build.gradle.kts):

plugins { alias(libs.plugins.android.application) } android { // ... defaultConfig { // app packageName,需要與控制台上的一樣 applicationId = "com.engagelab.app" // ... manifestPlaceholders.putAll(mapOf( // appKey,需要與控制台上的一樣,與packageName是一對一關係 "ENGAGELAB_PRIVATES_APPKEY" to "您的appkey", // Engagelab appChannel,用於渠道統計 "ENGAGELAB_PRIVATES_CHANNEL" to "developer", // Engagelab process,Engagelabsdk工作所在的進程,注意:開頭 "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 packageName,需要與控制台上的一樣
        applicationId = "com.engagelab.app"
        // ...

        manifestPlaceholders.putAll(mapOf(
            // appKey,需要與控制台上的一樣,與packageName是一對一關係
            "ENGAGELAB_PRIVATES_APPKEY" to "您的appkey",
            // Engagelab appChannel,用於渠道統計
            "ENGAGELAB_PRIVATES_CHANNEL" to "developer",
            // Engagelab process,Engagelabsdk工作所在的進程,注意:開頭
            "ENGAGELAB_PRIVATES_PROCESS" to ":remote"
        ))
    }
}

dependencies {
    implementation(fileTree(mapOf("include" to listOf("*.jar", "*.aar"), "dir" to "libs")))
}

            
此代碼塊在浮窗中顯示

3.創建必須組件

Java:

package com.engagelab.app.component; import com.engagelab.privates.common.component.MTCommonService; /** * 開發者繼承MTCommonService,可以使長連接更長時間存活 * <p> * 空實現即可 */ public class UserService extends MTCommonService { }
              
              package com.engagelab.app.component;

import com.engagelab.privates.common.component.MTCommonService;

/**
 * 開發者繼承MTCommonService,可以使長連接更長時間存活
 * <p>
 * 空實現即可
 */
public class UserService extends MTCommonService {

}

            
此代碼塊在浮窗中顯示

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

            
此代碼塊在浮窗中顯示

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; /** * 開發者繼承MTCommonReceiver,可以獲得sdk的方法回調 * <p> * 所有回調均在主線程 */ public class UserReceiver extends MTCommonReceiver { private static final String TAG = "UserReceiver"; /** * 應用通知開關狀態回調 * * @param context 不為空 * @param enable 通知開關是否開,true為打開,false為關閉 */ @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); } } /** * 長連接狀態回調 * * @param context 不為空 * @param enable 是否連接 */ @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); } // 長連接成功可獲取registrationId if (enable) { String registrationId = MTCorePrivatesApi.getRegistrationId(context); ExampleLogger.i(TAG, "registrationId:" + registrationId); } } /** * 通知消息到達回調 * * @param context 不為空 * @param notificationMessage 通知消息 */ @Override public void onNotificationArrived(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString()); } /** * 通知消息在前台不顯示 * * @param context 不為空 * @param notificationMessage 通知消息 */ @Override public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString()); } /** * 通知消息點擊回調 * * @param context 不為空 * @param notificationMessage 通知消息 */ @Override public void onNotificationClicked(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString()); } /** * 通知消息刪除回調 * * @param context 不為空 * @param notificationMessage 通知消息 */ @Override public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString()); } /** * 自定義消息回調 * * @param context 不為空 * @param customMessage 自定義消息 */ @Override public void onCustomMessage(Context context, CustomMessage customMessage) { ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString()); } /** * 廠商token消息回調 * * @param context 不為空 * @param platformTokenMessage 廠商token消息 */ @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;

/**
 * 開發者繼承MTCommonReceiver,可以獲得sdk的方法回調
 * <p>
 * 所有回調均在主線程
 */
public class UserReceiver extends MTCommonReceiver {

    private static final String TAG = "UserReceiver";

    /**
     * 應用通知開關狀態回調
     *
     * @param context 不為空
     * @param enable  通知開關是否開,true為打開,false為關閉
     */
    @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);
        }
    }

    /**
     * 長連接狀態回調
     *
     * @param context 不為空
     * @param enable  是否連接
     */
    @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);
        }
        // 長連接成功可獲取registrationId
        if (enable) {
            String registrationId = MTCorePrivatesApi.getRegistrationId(context);
            ExampleLogger.i(TAG, "registrationId:" + registrationId);
        }
    }

    /**
     * 通知消息到達回調
     *
     * @param context             不為空
     * @param notificationMessage 通知消息
     */
    @Override
    public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
    }

    /**
     * 通知消息在前台不顯示
     *
     * @param context             不為空
     * @param notificationMessage 通知消息
     */
    @Override
    public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString());
    }

    /**
     * 通知消息點擊回調
     *
     * @param context             不為空
     * @param notificationMessage 通知消息
     */
    @Override
    public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
    }

    /**
     * 通知消息刪除回調
     *
     * @param context             不為空
     * @param notificationMessage 通知消息
     */
    @Override
    public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
    }

    /**
     * 自定義消息回調
     *
     * @param context       不為空
     * @param customMessage 自定義消息
     */
    @Override
    public void onCustomMessage(Context context, CustomMessage customMessage) {
        ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
    }

    /**
     * 廠商token消息回調
     *
     * @param context              不為空
     * @param platformTokenMessage 廠商token消息
     */
    @Override
    public void onPlatformToken(Context context, PlatformTokenMessage platformTokenMessage) {
        ExampleLogger.i(TAG, "onPlatformToken:" + platformTokenMessage.toString());
    }

}

            
此代碼塊在浮窗中顯示

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 /** * 開發者繼承 MTCommonReceiver,可以獲得 SDK 的方法回調 * <p> * 所有回調均在主線程 */ class UserReceiver : MTCommonReceiver() { companion object { private const val TAG = "UserReceiver" } /** * 應用通知開關狀態回調 * * @param context 不為空 * @param enable 通知開關是否開啟,true 為打開,false 為關閉 */ 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) } /** * 長連接狀態回調 * * @param context 不為空 * @param enable 是否連接 */ 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) // 長連接成功可取得 registrationId if (enable) { val registrationId = MTCorePrivatesApi.getRegistrationId(context) ExampleLogger.i(TAG, "registrationId:$registrationId") } } /** * 通知訊息到達回調 * * @param context 不為空 * @param notificationMessage 通知訊息 */ override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}") } /** * 通知訊息在前台不顯示 * * @param context 不為空 * @param notificationMessage 通知訊息 */ override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}") } /** * 通知訊息點擊回調 * * @param context 不為空 * @param notificationMessage 通知訊息 */ override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}") } /** * 通知訊息刪除回調 * * @param context 不為空 * @param notificationMessage 通知訊息 */ override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}") } /** * 自訂訊息回調 * * @param context 不為空 * @param customMessage 自訂訊息 */ override fun onCustomMessage(context: Context, customMessage: CustomMessage) { ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}") } /** * 廠商 token 訊息回調 * * @param context 不為空 * @param platformTokenMessage 廠商 token 訊息 */ 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

/**
 * 開發者繼承 MTCommonReceiver,可以獲得 SDK 的方法回調
 * <p>
 * 所有回調均在主線程
 */
class UserReceiver : MTCommonReceiver() {

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

    /**
     * 應用通知開關狀態回調
     *
     * @param context 不為空
     * @param enable  通知開關是否開啟,true 為打開,false 為關閉
     */
    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)
    }

    /**
     * 長連接狀態回調
     *
     * @param context 不為空
     * @param enable  是否連接
     */
    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)
        // 長連接成功可取得 registrationId
        if (enable) {
            val registrationId = MTCorePrivatesApi.getRegistrationId(context)
            ExampleLogger.i(TAG, "registrationId:$registrationId")
        }
    }

    /**
     * 通知訊息到達回調
     *
     * @param context             不為空
     * @param notificationMessage 通知訊息
     */
    override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}")
    }

    /**
     * 通知訊息在前台不顯示
     *
     * @param context             不為空
     * @param notificationMessage 通知訊息
     */
    override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}")
    }

    /**
     * 通知訊息點擊回調
     *
     * @param context             不為空
     * @param notificationMessage 通知訊息
     */
    override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}")
    }

    /**
     * 通知訊息刪除回調
     *
     * @param context             不為空
     * @param notificationMessage 通知訊息
     */
    override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}")
    }

    /**
     * 自訂訊息回調
     *
     * @param context       不為空
     * @param customMessage 自訂訊息
     */
    override fun onCustomMessage(context: Context, customMessage: CustomMessage) {
        ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}")
    }

    /**
     * 廠商 token 訊息回調
     *
     * @param context              不為空
     * @param platformTokenMessage 廠商 token 訊息
     */
    override fun onPlatformToken(context: Context, platformTokenMessage: PlatformTokenMessage) {
        ExampleLogger.i(TAG, "onPlatformToken:${platformTokenMessage.toString()}")
    }

}

            
此代碼塊在浮窗中顯示

4.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"> <!-- 必須,網絡權限 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 可選,通知震動 --> <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"> <!-- 如果使用http請求,則需要允許使用http --> <!-- 由於此類具有長連接功能,手機廠商省電優化時可能直接殺死包名帶Engagelab字樣的service --> <!-- 所以需要開發者繼承com.engagelab.app.component.MTCommonService,提升長連接存活率,已達到提高消息到達率的目的 --> <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> <!-- 用於接收Engagelab業務的回調,包含了長連接狀態/通知開關狀態/通知消息到達/通知消息點擊/通知消息刪除/自定義消息/廠商token回調 --> <!-- 不需要配置子進程,此回調中在主進程中,方便業務操作 --> <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">
        
    <!-- 必須,網絡權限 -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- 可選,通知震動 -->
    <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"> <!-- 如果使用http請求,則需要允許使用http -->

        <!-- 由於此類具有長連接功能,手機廠商省電優化時可能直接殺死包名帶Engagelab字樣的service -->
        <!-- 所以需要開發者繼承com.engagelab.app.component.MTCommonService,提升長連接存活率,已達到提高消息到達率的目的 -->
        <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>

        <!-- 用於接收Engagelab業務的回調,包含了長連接狀態/通知開關狀態/通知消息到達/通知消息點擊/通知消息刪除/自定義消息/廠商token回調 -->
        <!-- 不需要配置子進程,此回調中在主進程中,方便業務操作 -->
        <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>

            
此代碼塊在浮窗中顯示

5.環境配置

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; /** * 用於演示ENGAGELAB-sdk配置 */ public class MainApplication extends Application { private static final String TAG = "MainApplication"; @Override public void onCreate() { super.onCreate(); // 必須在application.onCreate中配置,不要判斷進程,sdk內部有判斷 MTCorePrivatesApi.configDebugMode(this, true); // 初始化推送 // 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;

/**
 * 用於演示ENGAGELAB-sdk配置
 */
public class MainApplication extends Application {

    private static final String TAG = "MainApplication";

    @Override
    public void onCreate() {
        super.onCreate();


        // 必須在application.onCreate中配置,不要判斷進程,sdk內部有判斷
        MTCorePrivatesApi.configDebugMode(this, true);

        // 初始化推送
        // MTPushPrivatesApi.init(this);
    }

}

            
此代碼塊在浮窗中顯示

Kotlin:

package com.engagelab.app import android.app.Application import com.engagelab.privates.core.api.MTCorePrivatesApi import com.engagelab.privates.push.api.MTPushPrivatesApi /** * 用於演示 ENGAGELAB-sdk 配置 */ class MainApplication : Application() { companion object { private const val TAG = "MainApplication" } override fun onCreate() { super.onCreate() // 必須在 application.onCreate 中配置,不要判斷進程,sdk 內部有判斷 MTCorePrivatesApi.configDebugMode(this, true) // 初始化推送 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

/**
 * 用於演示 ENGAGELAB-sdk 配置
 */
class MainApplication : Application() {

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

    override fun onCreate() {
        super.onCreate()

        // 必須在 application.onCreate 中配置,不要判斷進程,sdk 內部有判斷
        MTCorePrivatesApi.configDebugMode(this, true)

        // 初始化推送
        MTPushPrivatesApi.init(this)
    }

}

            
此代碼塊在浮窗中顯示

6.創建通知點擊跳轉組件

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; /** * 用於演示-點擊通知後activity跳轉 * * 不需要調用{@link MTPushPrivatesApi#reportNotificationOpened(Context, String, byte, String)},sdk內部已做處理 */ 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; } //3.4.0版本開始不再使用對象,而使用json數據 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;

/**
 * 用於演示-點擊通知後activity跳轉
 *
 * 不需要調用{@link MTPushPrivatesApi#reportNotificationOpened(Context, String, byte, String)},sdk內部已做處理
 */
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;
            }
            //3.4.0版本開始不再使用對象,而使用json數據
            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();
        }
    }

}

            
此代碼塊在浮窗中顯示

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 /** * 用於演示-點擊通知後 activity 跳轉 * * 不需要調用 MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String),sdk 內部已做處理 */ 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 } // 3.4.0 版本開始不再使用對象,而使用 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

/**
 * 用於演示-點擊通知後 activity 跳轉
 *
 * 不需要調用 MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String),sdk 內部已做處理
 */
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
            }
            // 3.4.0 版本開始不再使用對象,而使用 json 數據
            val notificationMessage = intent.getStringExtra("message_json")
            if (notificationMessage == null) {
                return
            }
            ExampleLogger.d(TAG, "notificationMessage:$notificationMessage")
            tvMessage.text = notificationMessage
        } catch (throwable: Throwable) {
            throwable.printStackTrace()
        }
    }

}

            
此代碼塊在浮窗中顯示

7.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"> <!-- 必須,網絡權限 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 可選,通知震動 --> <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"> <!-- 如果使用http請求,則需要允許使用http --> .............................................................. <!-- 用於演示通知點擊跳轉 --> <activity android:name="com.engagelab.app.component.UserActivity400" android:exported="false" android:launchMode="singleTask" /> <!-- 用於演示deepLink的通知點擊跳轉 --> <!-- <activity--> <!-- android:name="com.engagelab.app.component.UserActivity400"--> <!-- android:exported="false" >--> <!-- <intent-filter>--> <!-- <data android:scheme="你的scheme"/>--> <!-- <data android:host="你的host"/>--> <!-- <action android:name="android.intent.action.VIEW" />--> <!-- <category android:name="android.intent.category.DEFAULT" />--> <!-- <category android:name="android.intent.category.BROWSABLE" />--> <!-- </intent-filter>--> <!-- </activity>--> <!--白名單本地中轉驗證:MTPush4.2.3版本開始,配置ENGAGELAB_PRIVATES_TRANSFER後,sdk會做本地驗證;不配置就不做本地驗證。如果開啟本地驗證,請將要跳轉的目標Activity配置在這裡;如果有多個目標Activity,請用/分割開。--> <meta-data android:name="ENGAGELAB_PRIVATES_TRANSFER" android:value="com.engagelab.app.component.UserActivity400" /> <!-- google push need,不需要 google 通道,则删除 --> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/mtpush_notification_icon" /> <!-- huawei push need,不需要 huawei 通道,则删除 --> <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">

    <!-- 必須,網絡權限 -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <!-- 可選,通知震動 -->
    <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"> <!-- 如果使用http請求,則需要允許使用http -->

        ..............................................................

        <!-- 用於演示通知點擊跳轉 -->
        <activity
            android:name="com.engagelab.app.component.UserActivity400"
            android:exported="false"
            android:launchMode="singleTask" />

        <!-- 用於演示deepLink的通知點擊跳轉 -->
<!--        <activity-->
<!--            android:name="com.engagelab.app.component.UserActivity400"-->
<!--            android:exported="false" >-->
<!--            <intent-filter>-->
<!--                <data android:scheme="你的scheme"/>-->
<!--                <data android:host="你的host"/>-->
<!--                <action android:name="android.intent.action.VIEW" />-->
<!--                <category android:name="android.intent.category.DEFAULT" />-->
<!--                <category android:name="android.intent.category.BROWSABLE" />-->
<!--            </intent-filter>-->
<!--        </activity>-->

            
        <!--白名單本地中轉驗證:MTPush4.2.3版本開始,配置ENGAGELAB_PRIVATES_TRANSFER後,sdk會做本地驗證;不配置就不做本地驗證。如果開啟本地驗證,請將要跳轉的目標Activity配置在這裡;如果有多個目標Activity,請用/分割開。-->
        <meta-data
            android:name="ENGAGELAB_PRIVATES_TRANSFER"
            android:value="com.engagelab.app.component.UserActivity400" />
                
        <!-- google push need,不需要 google 通道,则删除 -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/mtpush_notification_icon" />

        <!-- huawei push need,不需要 huawei 通道,则删除 -->
        <meta-data
            android:name="com.huawei.messaging.default_notification_icon"
            android:resource="@drawable/mtpush_notification_icon" />

    </application>

</manifest>

            
此代碼塊在浮窗中顯示
Icon Solid Transparent White Qiyu
聯繫銷售