메인 콘텐츠로 건너뛰기
  • Android
노티플라이 Android SDK에서는 푸시 알림이 표시되기 전에 알림의 설정을 커스터마이즈할 수 있는 인터셉터 기능을 제공합니다. 이를 통해 앱의 요구사항에 맞게 푸시 알림의 모양과 동작을 수정할 수 있습니다.
package com.your.project

import android.app.Application
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import tech.notifly.Notifly
import tech.notifly.push.interfaces.INotificationInterceptor
import tech.notifly.push.interfaces.IPushNotification

class SampleApplication : Application() {
  override fun onCreate() {
      super.onCreate()

      // Initialize Notifly SDK
      Notifly.initialize(
          context = applicationContext,
          projectId = BuildConfig.NOTIFLY_PROJECT_ID,
          username = BuildConfig.NOTIFLY_USERNAME,
          password = BuildConfig.NOTIFLY_PASSWORD,
      )

      // Add Notifly notification interceptor
      Notifly.addNotificationInterceptor(object : INotificationInterceptor {
          override fun postBuild(
              builder: NotificationCompat.Builder,
              notification: IPushNotification
          ): NotificationCompat.Builder {
              // Customize the notification here
              builder.setColor(ContextCompat.getColor(applicationContext, R.color.purple_700))
              // You can add more customizations based on your requirements
              return builder
          }
      })
  }
}

푸시 알림 인터셉터 인터페이스

  • Android
INotificationInterceptor 인터페이스의 postBuild 메서드를 구현하여 푸시 알림의 설정을 커스터마이즈할 수 있습니다. 이 메서드는 다음과 같은 파라미터를 받습니다:
  • builder: NotificationCompat.Builder: 현재 설정된 알림 빌더입니다. 이를 수정하여 알림의 모양과 동작을 변경할 수 있습니다.
  • notification: IPushNotification: 푸시 알림에 대한 정보를 담고 있는 객체입니다. 이를 통해 알림의 내용에 따라 다른 설정을 적용할 수 있습니다.
postBuild 메서드에서 원하는 설정을 builder에 적용한 후, 수정된 builder를 반환하면 됩니다.
Android 8.0 (API 레벨 26) 이상에서는 알림 채널 설정이 우선적으로 적용됩니다. 예를 들어, 알림 채널에 이미 소리가 설정되어 있다면, builder.setSound()로 설정한 소리는 무시될 수 있습니다. 알림의 주요 설정을 변경하려면 알림 채널 설정을 함께 고려해야 합니다.