리워드 지급 조건을 충족하면 유저에게 이를 알리기 위해 notification을 전송합니다. 앱에서 Notification을 수신하기 위해선 아래를 단계를 수행하세요.
drawable
디렉토리에 com_booster_notification_small_icon.xml
추가하여 자체 small icon을 설정할 수 있습니다. BuzzBooster Android SDK는 notification small icon을 설정하지 않을 경우 manifest에 등록된 application icon을 사용합니다.
<aside> 💡 Android 13 부터 notification 수신 시 유저 권한을 요청합니다. 자세한 문서는 다음을 참조하세요.
https://developer.android.com/about/versions/13/behavior-changes-13
</aside>
BuzzBooster는 FCM을 이용해 Push Notification을 전송합니다. 아래 단계를 따라 Firebase를 연동하고, 테스트하세요.
Firebase console에서 “프로젝트 만들기”를 선택해 프로젝트를 생성하세요.
프로젝트 개요 페이지에서 Android icon을 선택해 앱을 등록하세요.
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() } } |
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' ... } |
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' } |
<aside> 💡 최신 버전은 Firebase 문서를 참고하세요
</aside>
Reference.
Add Firebase to your Android project | Firebase for Android
<aside> 🚨 한 번만 다운 받을 수 있으니, 안전히 보관해주세요.
</aside>
사용자 기기 식별을 위한 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) } } } |
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> ... |
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 } } } |
c. Notification 클릭시 이동을 위해 MainActivity
에 아래 코드를 추가하세요.
... class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // ... if (BuzzBooster.hasUnhandledNotificationClick(this)) { BuzzBooster.handleNotification(this) } } } |
버즈부스터 대시에서 연동이 잘 되었는지 확인하세요.