Android Firebase Cloud Messaging(FCM) 사용 2
사용 버전: Android Studio 4.0.2
사용 언어: Kotlin 1.4.10
Android Firebase Cloud Messaging(FCM) 사용 1에 이어서 진행됩니다.
앱 프로젝트 내에 서비스 클래스를 하나 만듭니다.
저는 RestAreaFCMService로 만들었습니다.
사용 언어: Kotlin 1.4.10
안드로이드 Firebase Cloud Messaging(FCM) 사용 2를 해보겠습니다.
Android Firebase Cloud Messaging(FCM) 사용 1에 이어서 진행됩니다.
앱 프로젝트 내에 서비스 클래스를 하나 만듭니다.
저는 RestAreaFCMService로 만들었습니다.

FirebaseMessagingService를 상속받고 override 합니다.

그리고 메시지를 받으면 알림을 주기 위해서 Notification 사용이 필요합니다.
아래 코드를 이용해서, FCM 용 채널을 하나 만듭니다.

아래처럼 설정합니다.

다시 RestAreaFCMService로 돌아옵니다.
아래처럼 수정합니다.

이제, manifests로 갑니다.
<application> </application>태그 사이에 <service>를
추가합니다.

그리고 아래에 meta-data를 추가합니다.

실행합니다.
토큰을 얻게 됩니다.

위의 토큰으로 테스트할 때 사용할 수 있습니다.
한 번 생성되면, 앱을 삭제할 때까지 유지됩니다. 토큰을 못 봤다면, 다시 지우고
설치해 주세요.
Firebase Console로 돌아옵니다.
왼쪽 메뉴에 보면, Cloud Messaging이 보입니다.

클릭합니다.
Send your first message를 누릅니다.

알림 제목, 알림 텍스트를 입력하면 테스트 메시지 전송이 활성화됩니다.

테스트는 진행해도 되고, 바로 보내도 됩니다.
테스트에 위의 토큰이 사용됩니다.
테스트를 누르면 아래 창이 나옵니다.

+를 누르고 테스트를 누릅니다.

다음과 같이 전송된 것이 보입니다.

다음을 누릅니다.

타깃을 선택합니다.

예약도 설정합니다.

추가 옵션을 적습니다. 저는 안 적었습니다.

검토를 누르면 아래 창이 나옵니다.

Analytics를 연결하지 않아서 저런 빨간 알림 창이 나옵니다.
게시를 누릅니다.
보낸 결과 창이 나옵니다.

앱에 알림이 도착합니다.

알림을 누르면 앱이 열립니다.

앱이 열려 있을 때에도 알림이 표시됩니다.

Android Firebase Cloud Messaging(FCM) 사용 3으로 이어집니다.
끝.
카테고리: Android
댓글
댓글 쓰기
궁금한 점은 댓글 달아주세요.
Comment if you have any questions.