Skip to content

การปรับแต่งการแจ้งเตือน

เนื่องจาก SORI SDK มี foreground service จึงมีการแจ้งเตือนเริ่มต้นที่จะแสดงขณะ service ทำงาน อย่างไรก็ตาม คุณสามารถปรับแต่งการแจ้งเตือนนี้ให้เหมาะกับแบรนด์และประสบการณ์ผู้ใช้ของแอปมากขึ้นได้

หากต้องการปรับแต่งการแจ้งเตือน ให้ใช้ method startRecognition ของคลาส SORIAudioRecognizer method นี้ช่วยให้คุณกำหนด title, body และ icon ของการแจ้งเตือนได้

kotlin
val audioRecognizer = SORIAudioRecognizer()
// ...
audioRecognizer.startRecognition(
    this,
    title = "Custom Title",
    body = "Custom Body",
    icon = R.drawable.custom_icon
)
java
SORIAudioRecognizer audioRecognizer = new SORIAudioRecognizer();
// ...
audioRecognizer.startRecognition(
    this,
    "Custom Title",
    "Custom Body",
    R.drawable.custom_icon
);

หากต้องการควบคุมการแจ้งเตือนเพิ่มเติม คุณสามารถนำ SORIAudioRecognizer.NotificationProvider ไปใช้กับคลาส SORIAudioRecognizer ซึ่งช่วยให้สร้างการแจ้งเตือนแบบกำหนดเองโดยใช้คลาส NotificationCompat.Builder ได้ ให้นำ method build ของ interface NotificationProvider ไปใช้เพื่อสร้างการแจ้งเตือนแบบกำหนดเอง

kotlin
val notificationProvider = object : SORIAudioRecognizer.NotificationProvider {
    override fun build(builder: NotificationCompat.Builder): Notification {
        return builder
            .setContentTitle("Custom Title")
            .setContentText("Custom Body")
            .setSmallIcon(R.drawable.custom_icon)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setContentIntent(pendingIntent)
            // Add any other customizations you want
    }
}

SORIAudioRecognizer.notificationProvider = notificationProvider