1. 앱이 실행중일때에는 앱에서 메세지를 수신받으므로, 코드를 통해 커스텀으로 재생 가능.
2. 앱이 background 혹은 실행중이 아닐경우, 서버에서 특정 기기로 요청시, 개발을 다르게 진행해야함.
- FirebaseMessagingService를 상속받은 클래스에서, onMessageReceived를 override를 받아야 함. (Foreground일 경우에도 마찬가지)
- remoteMessage.getData() 를 통해 접근시, 앱이 background나 실행중이 아닐경우에도 코드를 실행할 수 있음.
- 따라서, foreground Push가 왔을경우 함수 호출을 해주면 됨.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if(remoteMessage.getNotification()!= null)
{
sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}else if(remoteMessage.getData().size() > 0)
{
sendNotification(remoteMessage.getData().get("title"),remoteMessage.getData().get("body"));
}
}
3. 서버에서 FCM으로 Push 요청을 보낼 때에는 기존 Notification 함수가 아니라 Data 함수에 title과 body를 실어서 보내야함.
'Android' 카테고리의 다른 글
| UI 배치 관련 내용 정리 (constraintLayout) (0) | 2022.05.18 |
|---|---|
| 갤럭시 워치 통신을 위한 arr 프로젝트 및 Unity Demo 프로젝트 내용정리 (0) | 2022.03.25 |
| Android SNS 로그인 (카카오톡) (0) | 2022.03.24 |
| Android SNS 로그인 (구글) (0) | 2022.03.24 |
| Android 콜백 구현 (0) | 2022.03.24 |