Skip to content

Latest commit

 

History

History
48 lines (40 loc) · 1.51 KB

File metadata and controls

48 lines (40 loc) · 1.51 KB

Firebase Messaging

Gradle Setting

compile "com.google.firebase:firebase-messaging:${version.firebase}"

Service Register [ Manifests ]

 <service android:name=".fcm.FCMInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".fcm.FCMMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
  • Firebase Key, Firebase Message 수신을 위해 Service를 등록한다

FirebaseInstanceId Service

@Override
    public void onTokenRefresh() {
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d("FCMInstanceService", "Refreshed token: " + refreshedToken);
    }

Firebase Messaging Service

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    
    // Notification 등록
    RemoteMessage.Notification notification = remoteMessage.getNotification();
    NotificationUtils.sendNotification(this, notification.getTitle(), notification.getBody());
}