Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

배워보자~

[Android] FCM Message 사용기 팁 본문

Android

[Android] FCM Message 사용기 팁

벽면 수도 2017. 3. 14. 16:15

[Android] FCM Message 사용기 팁

※ 기본적인 개념은 구글 Guide 문서 참조 

FCM Message 종류는 2가지가 존재함. 
  • 알림 메세지 :  '디스플레이 메시지'로 간주할 수 있습니다.  json format에서 notification 노드가 존재하는 메세지 
  • 데이타 메세지 : 클라이언트 앱에서 처리 합니다. son format에서 data 노드가 존재하는 메세지 혹은 notification노드가 없어야 함.

2개의 메세지의 차이점

 

 data message

notification message 

 json format

 data 키만 존재함. 

notification 키 필수, (data 키 같이 사용가능) 

 son format 예시 

 {

"to" : "[fcm_key]",

"collapse_key" : "demo",

"priority"     : "normal",

"data" : {

"body"   : "3.21.15",

"title"   : "3.21.15",

"volume"   : "3.21.15",

"contents" : "xXx"

}

} 


* data 노드의 key값은 개발자 임의값 사용

 {

"to" : "[fcm_key]",

"collapse_key" : "demo",

"priority"     : "normal",

"notification" : {

"body"  : "This week's edition is now available.",

"title" : "NewsMagazine.com",

"icon"  : "new"

"sound" : "default"

},

"data" : { /* 있어도 되고 없어도 됨 */

"volume"   : "3.21.15",

"contents" : "xXx"

}

}


* notification 노드의 key값은 정해져 있음. 구글 가이드 참조


 클라이언트(앱)에서 사용 시

 FirebaseMessagingService.onMessageReceived(RemoteMessage remoteMessage) 호출 여부

 앱 background

 호출 됨. 

 호출 않 됨 

(하지만, 시스템에서 처리 함-자동으로 notification bar에 표시) 

 앱 foreground

 호출 됨. 

 호출됨. 
  개발자가 알아서 처리