안드로이드

Firebase 설정, firebase콘솔에 앱등록

코딩하는후운 2022. 11. 4. 16:06
반응형

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?: "")

            })
반응형