Search
Duplicate

7. Push Notification 연동

BuzzBooster SDK로 Notification을 수신

리워드 지급 조건을 충족하면 유저에게 이를 알리기 위해 notification을 전송합니다. 앱에서 Notification을 수신하기 위해선 아래를 단계를 수행하세요.

Notification Icon 설정

drawable 디렉토리에 com_booster_notification_small_icon.xml 추가하여 자체 small icon을 설정할 수 있습니다. BuzzBooster Android SDK는 notification small icon을 설정하지 않을 경우 manifest에 등록된 application icon을 사용합니다.
Android 13 부터 notification 수신 시 유저 권한을 요청합니다. 자세한 문서는 다음을 참조하세요.

Firebase Cloud Messaging (FCM)

BuzzBooster는 FCM을 이용해 Push Notification을 전송합니다. 아래 단계를 따라 Firebase를 연동하고, 테스트하세요.

Step 1. Firebase 연동

1. Firebase 프로젝트 생성

Firebase console에서 “프로젝트 만들기”를 선택해 프로젝트를 생성하세요.

2. Firebase 프로젝트에 앱 등록

프로젝트 개요 페이지에서 Android icon을 선택해 앱을 등록하세요.

3. Firebase 설정 파일을 앱에 추가

a. google-services.json 파일을 다운받고, 해당 파일을 module (app-level) 루트 폴더로 옮기세요.
b. Project Gradle 파일(<project>/build.gradle)에 아래 내용을 추가하세요.
buildscript { repositories { // Make sure that you have the following two repositories google() mavenCentral() } dependencies { ... // Add the dependency for the Google services Gradle plugin classpath 'com.google.gms:google-services:4.3.14' } } allprojects { ... repositories { // Make sure that you have the following two repositories google() mavenCentral() } }
Groovy
복사
c. Module Gradle 파일(보통 <project>/<app-module>/build.gradle)에 아래 내용을 추가하세요.
plugins { id 'com.android.application' // Add the Google services Gradle plugin id 'com.google.gms.google-services' ... }
Groovy
복사

4. Firebase Cloud Messaging SDK를 앱에 추가

Module Gradle 파일(보통 <project>/<app-module>/build.gradle)에 아래 내용을 추가하세요.
dependencies { ... implementation 'com.google.firebase:firebase-messaging:x.y.z' implementation 'com.google.gms:google-services:x.y.z' }
Groovy
복사
최신 버전은 Firebase 문서를 참고하세요
Reference.

Step 2. BuzzBooster 대시 연동

1. Firebase console의 프로젝트 설정으로 이동하세요.

2. 클라우드 메시징으로 이동해 서비스 계정 관리를 클릭하세요.

3. firebase로 시작하는 이메일을 클릭하세요.

4. 키 - 키 추가 - 새 키 만들기를 클릭하세요.

5. JSON 형식으로 만들기를 눌러, 파일을 다운로드 받아주세요.

한 번만 다운 받을 수 있으니, 안전히 보관해주세요.

6. BuzzBooster 대시보드 - Integration - Push에서 업로드 해주세요.

Step 3. BuzzBooster SDK 연동

1. Firebase Cloud Messaging token 등록

사용자 기기 식별을 위한 token을 등록하세요.
... import android.app.Application import com.buzzvil.booster.external.BuzzBooster import com.buzzvil.booster.external.BuzzBoosterConfig import com.google.firebase.messaging.FirebaseMessaging class App : Application() { override fun onCreate() { super.onCreate() val buzzBoosterConfig = BuzzBoosterConfig(MY_APP_KEY) BuzzBooster.init(applicationContext, buzzBoosterConfig) // Add below lines to set FCM token FirebaseMessaging.getInstance().token.addOnSuccessListener { BuzzBooster.setFCMToken(it) } } }
Kotlin
복사

2. Notification 처리하기

a. AndroidManifest.xml에 메세지 처리를 위한 서비스 등록
... <application ...> <service android:name=".MyFirebaseMessagingService" android:exported="false"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> ... </application> ...
XML
복사
b. MyFirebaseMessagingService.kt 서비스 구현
... import com.buzzvil.booster.external.BuzzBooster import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage class MyFirebaseMessagingService : FirebaseMessagingService() { override fun onNewToken(token: String) { BuzzBooster.setFCMToken(token) // Enter your code } override fun onMessageReceived(message: RemoteMessage) { val data = message.data if (BuzzBooster.isBuzzBoosterNotification(data)) { BuzzBooster.handleNotification(data) } else { // Enter your code } } }
Kotlin
복사
c. Notification 클릭시 이동을 위해 MainActivity에 아래 코드를 추가하세요.
... class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ... if (BuzzBooster.hasUnhandledNotificationClick(this)) { BuzzBooster.handleNotification(this) } } }
Kotlin
복사

Step 4. 테스트

버즈부스터 대시에서 연동이 잘 되었는지 확인하세요.