คู่มือการผสานรวมช่องทาง Engagelab

泰语

# คู่มือการรวมช่องทาง Engagelab ## รับข้อมูลแอปพลิเคชัน สร้างแอปพลิเคชันในคอนโซล หลังจากสร้างแอปพลิเคชันเสร็จแล้ว จะมีการสร้าง AppKey โดยอัตโนมัติเพื่อระบุแอปพลิเคชันนี้ สำหรับข้อมูลเพิ่มเติม โปรดดูที่ [การตั้งค่าแอปพลิเคชัน](/th_TH/docs/app-push/console/basic-settings/app-info) ## นำเข้าไลบรารี - วิธีการแบบแมนนวล
              
              # คู่มือการรวมช่องทาง Engagelab
## รับข้อมูลแอปพลิเคชัน
สร้างแอปพลิเคชันในคอนโซล หลังจากสร้างแอปพลิเคชันเสร็จแล้ว จะมีการสร้าง AppKey โดยอัตโนมัติเพื่อระบุแอปพลิเคชันนี้ สำหรับข้อมูลเพิ่มเติม โปรดดูที่ [การตั้งค่าแอปพลิเคชัน](/th_TH/docs/app-push/console/basic-settings/app-info)
## นำเข้าไลบรารี

- วิธีการแบบแมนนวล  

            
โค้ดนี้โชว์เป็นหน้าต่างลอย
นำเข้า 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 ไปยังไดเรกทอรี libs

            
โค้ดนี้โชว์เป็นหน้าต่างลอย
- วิธีการอัตโนมัติ **Groovy (build.gradle):** ```groovy 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 // ตัวเลือก: ผู้ผลิต Xiaomi, เวอร์ชันภาษาจีน implementation 'com.engagelab.plugin:mi:5.3.0' // ตัวอย่างเวอร์ชัน 5.3.0 // ตัวเลือก: ผู้ผลิต Meizu implementation 'com.engagelab.plugin:meizu:5.3.0' // ตัวอย่างเวอร์ชัน 5.3.0 // ผู้ผลิต Meizu: ตั้งแต่ SDK 5.2.0 การรวม Meizu ต้องใช้ "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 // ตัวเลือก: ฟังก์ชันเสียงประกาศ implementation 'com.engagelab.plugin:oth_sound:5.3.0' // ตัวอย่างเวอร์ชัน 5.3.0 }
              
              
- วิธีการอัตโนมัติ

**Groovy (build.gradle):**
```groovy
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
  // ตัวเลือก: ผู้ผลิต Xiaomi, เวอร์ชันภาษาจีน
  implementation 'com.engagelab.plugin:mi:5.3.0' // ตัวอย่างเวอร์ชัน 5.3.0
  // ตัวเลือก: ผู้ผลิต Meizu
  implementation 'com.engagelab.plugin:meizu:5.3.0' // ตัวอย่างเวอร์ชัน 5.3.0
  // ผู้ผลิต Meizu: ตั้งแต่ SDK 5.2.0 การรวม Meizu ต้องใช้ "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
  // ตัวเลือก: ฟังก์ชันเสียงประกาศ
  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 // ตัวเลือก: ผู้ผลิต Xiaomi, เวอร์ชันภาษาจีน implementation("com.engagelab.plugin:mi:5.3.0") // ตัวอย่างเวอร์ชัน 5.3.0 // ตัวเลือก: ผู้ผลิต Meizu implementation("com.engagelab.plugin:meizu:5.3.0") // ตัวอย่างเวอร์ชัน 5.3.0 // ผู้ผลิต Meizu: ตั้งแต่ SDK 5.2.0 การรวม Meizu ต้องใช้ "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 // ตัวเลือก: ฟังก์ชันเสียงประกาศ 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
    // ตัวเลือก: ผู้ผลิต Xiaomi, เวอร์ชันภาษาจีน
    implementation("com.engagelab.plugin:mi:5.3.0") // ตัวอย่างเวอร์ชัน 5.3.0
    // ตัวเลือก: ผู้ผลิต Meizu
    implementation("com.engagelab.plugin:meizu:5.3.0") // ตัวอย่างเวอร์ชัน 5.3.0
    // ผู้ผลิต Meizu: ตั้งแต่ SDK 5.2.0 การรวม Meizu ต้องใช้ "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
    // ตัวเลือก: ฟังก์ชันเสียงประกาศ
    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 { // ชื่อแพ็คเกจแอปพลิเคชัน ต้องตรงกับในคอนโซล applicationId "com.engagelab.app" ... manifestPlaceholders = [ // AppKey ต้องตรงกับในคอนโซล และตรงกับ packageName ENGAGELAB_PRIVATES_APPKEY : "YourAppKey", // ช่องทาง Engagelab สำหรับการวิเคราะห์ช่องทาง ENGAGELAB_PRIVATES_CHANNEL: "developer", // กระบวนการ Engagelab ที่ SDK ของ Engagelab ทำงานอยู่ หมายเหตุ: ต้องเริ่มต้นด้วย : ENGAGELAB_PRIVATES_PROCESS: ":remote", ] } } dependencies { implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') }
              
              plugins {
    id 'com.android.application'
}

android {
    ...

    defaultConfig {
        // ชื่อแพ็คเกจแอปพลิเคชัน ต้องตรงกับในคอนโซล
        applicationId "com.engagelab.app"
        ...
                
        manifestPlaceholders = [
                // AppKey ต้องตรงกับในคอนโซล และตรงกับ packageName
                ENGAGELAB_PRIVATES_APPKEY : "YourAppKey",
                // ช่องทาง Engagelab สำหรับการวิเคราะห์ช่องทาง
                ENGAGELAB_PRIVATES_CHANNEL: "developer",
                // กระบวนการ Engagelab ที่ SDK ของ Engagelab ทำงานอยู่ หมายเหตุ: ต้องเริ่มต้นด้วย :
                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 { // ชื่อแพ็คเกจแอปพลิเคชัน ต้องตรงกับในคอนโซล applicationId = "com.engagelab.app" // ... manifestPlaceholders.putAll(mapOf( // AppKey ต้องตรงกับในคอนโซล และตรงกับ packageName "ENGAGELAB_PRIVATES_APPKEY" to "YourAppKey", // ช่องทาง Engagelab สำหรับการวิเคราะห์ช่องทาง "ENGAGELAB_PRIVATES_CHANNEL" to "developer", // กระบวนการ Engagelab ที่ SDK ของ Engagelab ทำงานอยู่ หมายเหตุ: ต้องเริ่มต้นด้วย : "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 {
        // ชื่อแพ็คเกจแอปพลิเคชัน ต้องตรงกับในคอนโซล
        applicationId = "com.engagelab.app"
        // ...

        manifestPlaceholders.putAll(mapOf(
            // AppKey ต้องตรงกับในคอนโซล และตรงกับ packageName
            "ENGAGELAB_PRIVATES_APPKEY" to "YourAppKey",
            // ช่องทาง Engagelab สำหรับการวิเคราะห์ช่องทาง
            "ENGAGELAB_PRIVATES_CHANNEL" to "developer",
            // กระบวนการ Engagelab ที่ SDK ของ Engagelab ทำงานอยู่ หมายเหตุ: ต้องเริ่มต้นด้วย :
            "ENGAGELAB_PRIVATES_PROCESS" to ":remote"
        ))
    }
}

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

            
โค้ดนี้โชว์เป็นหน้าต่างลอย

สร้างคอมโพเนนต์ที่จำเป็น

Java:

package com.engagelab.app.component; import com.engagelab.privates.common.component.MTCommonService; /** * นักพัฒนาสามารถสืบทอด MTCommonService เพื่อขยายอายุการใช้งานของการเชื่อมต่อแบบยาว * * สามารถเว้นว่างได้ */ public class UserService extends MTCommonService { }
              
              package com.engagelab.app.component;

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

/**
 * นักพัฒนาสามารถสืบทอด MTCommonService เพื่อขยายอายุการใช้งานของการเชื่อมต่อแบบยาว
 *
 * สามารถเว้นว่างได้
 */
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 * * การเรียกกลับทั้งหมดจะอยู่ในเธรดหลัก */ public class UserReceiver extends MTCommonReceiver { private static final String TAG = "UserReceiver"; /** * การเรียกกลับสถานะการเปิด/ปิดการแจ้งเตือน * * @param context ไม่เป็น null * @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 ไม่เป็น null * @param enable สถานะการเชื่อมต่อ true คือเชื่อมต่อ false คือไม่เชื่อมต่อ */ @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 ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ @Override public void onNotificationArrived(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString()); } /** * การเรียกกลับเมื่อไม่แสดงข้อความแจ้งเตือนในโหมดหน้าจอหน้า * * @param context ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ @Override public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString()); } /** * การเรียกกลับเมื่อมีการคลิกข้อความแจ้งเตือน * * @param context ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ @Override public void onNotificationClicked(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString()); } /** * การเรียกกลับเมื่อมีการลบข้อความแจ้งเตือน * * @param context ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ @Override public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) { ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString()); } /** * การเรียกกลับข้อความที่กำหนดเอง * * @param context ไม่เป็น null * @param customMessage ข้อความที่กำหนดเอง */ @Override public void onCustomMessage(Context context, CustomMessage customMessage) { ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString()); } /** * การเรียกกลับข้อความ token ของผู้ผลิต * * @param context ไม่เป็น null * @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
 *
 * การเรียกกลับทั้งหมดจะอยู่ในเธรดหลัก
 */
public class UserReceiver extends MTCommonReceiver {

    private static final String TAG = "UserReceiver";

    /**
     * การเรียกกลับสถานะการเปิด/ปิดการแจ้งเตือน
     *
     * @param context ไม่เป็น null
     * @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 ไม่เป็น null
     * @param enable สถานะการเชื่อมต่อ true คือเชื่อมต่อ false คือไม่เชื่อมต่อ
     */
    @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 ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    @Override
    public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
    }

    /**
     * การเรียกกลับเมื่อไม่แสดงข้อความแจ้งเตือนในโหมดหน้าจอหน้า
     *
     * @param context ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    @Override
    public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString());
    }

    /**
     * การเรียกกลับเมื่อมีการคลิกข้อความแจ้งเตือน
     *
     * @param context ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    @Override
    public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
    }

    /**
     * การเรียกกลับเมื่อมีการลบข้อความแจ้งเตือน
     *
     * @param context ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    @Override
    public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
        ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
    }

    /**
     * การเรียกกลับข้อความที่กำหนดเอง
     *
     * @param context ไม่เป็น null
     * @param customMessage ข้อความที่กำหนดเอง
     */
    @Override
    public void onCustomMessage(Context context, CustomMessage customMessage) {
        ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
    }

    /**
     * การเรียกกลับข้อความ token ของผู้ผลิต
     *
     * @param context ไม่เป็น null
     * @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 * การเรียกกลับทั้งหมดจะอยู่ในเธรดหลัก */ class UserReceiver : MTCommonReceiver() { companion object { private const val TAG = "UserReceiver" } /** * การเรียกกลับสถานะการเปิด/ปิดการแจ้งเตือน * * @param context ไม่เป็น null * @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 ไม่เป็น null * @param enable สถานะการเชื่อมต่อ true คือเชื่อมต่อ false คือไม่เชื่อมต่อ */ 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 ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}") } /** * การเรียกกลับเมื่อไม่แสดงข้อความแจ้งเตือนในโหมดหน้าจอหน้า * * @param context ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}") } /** * การเรียกกลับเมื่อมีการคลิกข้อความแจ้งเตือน * * @param context ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}") } /** * การเรียกกลับเมื่อมีการลบข้อความแจ้งเตือน * * @param context ไม่เป็น null * @param notificationMessage ข้อความแจ้งเตือน */ override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) { ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}") } /** * การเรียกกลับข้อความที่กำหนดเอง * * @param context ไม่เป็น null * @param customMessage ข้อความที่กำหนดเอง */ override fun onCustomMessage(context: Context, customMessage: CustomMessage) { ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}") } /** * การเรียกกลับข้อความ token ของผู้ผลิต * * @param context ไม่เป็น null * @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
 * การเรียกกลับทั้งหมดจะอยู่ในเธรดหลัก
 */
class UserReceiver : MTCommonReceiver() {

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

    /**
     * การเรียกกลับสถานะการเปิด/ปิดการแจ้งเตือน
     *
     * @param context ไม่เป็น null
     * @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 ไม่เป็น null
     * @param enable  สถานะการเชื่อมต่อ true คือเชื่อมต่อ false คือไม่เชื่อมต่อ
     */
    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             ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}")
    }

    /**
     * การเรียกกลับเมื่อไม่แสดงข้อความแจ้งเตือนในโหมดหน้าจอหน้า
     *
     * @param context             ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}")
    }

    /**
     * การเรียกกลับเมื่อมีการคลิกข้อความแจ้งเตือน
     *
     * @param context             ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}")
    }

    /**
     * การเรียกกลับเมื่อมีการลบข้อความแจ้งเตือน
     *
     * @param context             ไม่เป็น null
     * @param notificationMessage ข้อความแจ้งเตือน
     */
    override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) {
        ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}")
    }

    /**
     * การเรียกกลับข้อความที่กำหนดเอง
     *
     * @param context        ไม่เป็น null
     * @param customMessage  ข้อความที่กำหนดเอง
     */
    override fun onCustomMessage(context: Context, customMessage: CustomMessage) {
        ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}")
    }

    /**
     * การเรียกกลับข้อความ token ของผู้ผลิต
     *
     * @param context               ไม่เป็น null
     * @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" โดยตรง --> <!-- ดังนั้นนักพัฒนาจำเป็นต้องขยาย 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 รวมถึงสถานะการเชื่อมต่อระยะยาว/สถานะสวิตช์การแจ้งเตือน/การมาถึงของข้อความแจ้งเตือน/การคลิกข้อความแจ้งเตือน/การลบข้อความแจ้งเตือน/ข้อความที่กำหนดเอง/การเรียกกลับโทเค็นของผู้ให้บริการ --> <!-- ไม่จำเป็นต้องกำหนดค่ากระบวนการย่อย การเรียกกลับนี้อยู่ในกระบวนการหลักเพื่อความสะดวกในการดำเนินการทางธุรกิจ --> <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" โดยตรง -->
        <!-- ดังนั้นนักพัฒนาจำเป็นต้องขยาย 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 รวมถึงสถานะการเชื่อมต่อระยะยาว/สถานะสวิตช์การแจ้งเตือน/การมาถึงของข้อความแจ้งเตือน/การคลิกข้อความแจ้งเตือน/การลบข้อความแจ้งเตือน/ข้อความที่กำหนดเอง/การเรียกกลับโทเค็นของผู้ให้บริการ -->
        <!-- ไม่จำเป็นต้องกำหนดค่ากระบวนการย่อย การเรียกกลับนี้อยู่ในกระบวนการหลักเพื่อความสะดวกในการดำเนินการทางธุรกิจ -->
        <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 ไม่ต้องตรวจสอบ process 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 ไม่ต้องตรวจสอบ process 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 * * ไม่จำเป็นต้องเรียก 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
 *
 * ไม่จำเป็นต้องเรียก 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 ไม่ใช้ object อีกต่อไป ใช้ข้อมูล 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 ไม่ใช้ object อีกต่อไป ใช้ข้อมูล 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" /> <!-- ใช้เพื่อแสดงการคลิกแจ้งเตือนด้วยลิงก์ลึก --> <!-- <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>--> <!-- การตรวจสอบการถ่ายโอนในพื้นที่ที่อนุญาต: เริ่มต้นจาก MTPush 4.2.3 หลังจากกำหนดค่า ENGAGELAB_PRIVATES_TRANSFER SDK จะทำการตรวจสอบในพื้นที่ หากเปิดใช้งานการตรวจสอบในพื้นที่ โปรดกำหนดค่า Activity เป้าหมายที่จะข้ามไปที่นี่ หากมี Activity เป้าหมายหลายรายการ โปรดแยกด้วย / --> <meta-data android:name="ENGAGELAB_PRIVATES_TRANSFER" android:value="com.engagelab.app.component.UserActivity400" /> <!-- ความต้องการของ Google push: ลบออกหากไม่ต้องการช่องทาง Google --> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/mtpush_notification_icon" /> <!-- ความต้องการของ Huawei push: ลบออกหากไม่ต้องการช่องทาง 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" />

        <!-- ใช้เพื่อแสดงการคลิกแจ้งเตือนด้วยลิงก์ลึก -->
<!--        <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>-->

            
        <!-- การตรวจสอบการถ่ายโอนในพื้นที่ที่อนุญาต: เริ่มต้นจาก MTPush 4.2.3 หลังจากกำหนดค่า ENGAGELAB_PRIVATES_TRANSFER SDK จะทำการตรวจสอบในพื้นที่ หากเปิดใช้งานการตรวจสอบในพื้นที่ โปรดกำหนดค่า Activity เป้าหมายที่จะข้ามไปที่นี่ หากมี Activity เป้าหมายหลายรายการ โปรดแยกด้วย / -->
        <meta-data
            android:name="ENGAGELAB_PRIVATES_TRANSFER"
            android:value="com.engagelab.app.component.UserActivity400" />
                
        <!-- ความต้องการของ Google push: ลบออกหากไม่ต้องการช่องทาง Google -->
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/mtpush_notification_icon" />

        <!-- ความต้องการของ Huawei push: ลบออกหากไม่ต้องการช่องทาง Huawei -->
        <meta-data
            android:name="com.huawei.messaging.default_notification_icon"
            android:resource="@drawable/mtpush_notification_icon" />

    </application>

</manifest>

            
โค้ดนี้โชว์เป็นหน้าต่างลอย
Icon Solid Transparent White Qiyu
ติดต่อฝ่ายขาย