반응형
Firebase 설정
firebase콘솔에 앱등록
-google-services.json 다운받아서 앱에 넣기
매니페스트
<service android:name=".fcm.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
See README (https://goo.gl/l4GJaQ) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_launcher_foreground" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. See README(https://goo.gl/6BKBk7) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
token 가져오기
FirebaseInstanceId.getInstance().instanceId
.addOnCompleteListener(OnCompleteListener { task ->
if(!task.isSuccessful){
Log.w(tag, "getInstanceId failed", task.exception)
return@OnCompleteListener
}
// Get new Instance ID token
val token = task.result?.token
//Log and toast
LogUtil.d(tag, "fcm token : $token")
AppApplication.getAppPreference().setString(Keys.KEY_FCM_TOKEN, token?: "")
})
반응형
'안드로이드' 카테고리의 다른 글
[Android] Fragment commit commitNow 차이 (0) | 2022.11.04 |
---|---|
[Android] Fragment replace add 차이 (0) | 2022.11.04 |
[Android] EventBus, RxEventBus 사용법 (0) | 2022.10.27 |
[Android] Dependency, Dependency Injection (0) | 2022.10.27 |
[Android] DI란?, Dagger2 사용법에 대해 알아보자 (0) | 2022.10.27 |