0

으로 마이그레이션 한 후 FCM 콜백 핸들러가 실행되지 않습니다. here과 같이 GCM에서 FCM으로 이전했습니다.gcm에서 fcm

메시지를 보낼 때마다 onMessageSent 메서드가 호출되지 않습니다. 왜 작동하지 않는

Map<String,String> data = new HashMap<String,String>(); 
     data.put(GcmConstants.ACTION, GcmConstants.ACTION_CHAT); 
     data.put(Constants.CHAT_FLAG, Constants.FLAG_NEW_CHAT); 

     ObjectMapper mapper = new ObjectMapper(); 
     String chatJsonInString = mapper.writeValueAsString(Helper.chatToJson(chat)); 

     data.put(Constants.CHAT_JSON, chatJsonInString); 

     String receiverJsonInString = mapper.writeValueAsString(Helper.userToJson(receiver)); 
     data.put(Constants.RECEIVER_JSON, receiverJsonInString); 

     String id = Integer.toString(getNextMsgId(ctxt)); 
     FirebaseMessaging fm = FirebaseMessaging.getInstance(); 
     fm.send(new RemoteMessage.Builder(senderId + "@gcm.googleapis.com").setMessageId(id).setData(data).build()); 

:

나는 메시지를 보낼 소스 코드를 다음 사용합니까? onMessageReceived의 시작

@Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     // [START_EXCLUDE] 
     // There are two types of messages data messages and notification messages. Data messages are handled 
     // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type 
     // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app 
     // is in the foreground. When the app is in the background an automatically generated notification is displayed. 
     // When the user taps on the notification they are returned to the app. Messages containing both notification 
     // and data payloads are treated as notification messages. The Firebase console always sends notification 
     // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options 
     // [END_EXCLUDE] 

// TODO(developer): Handle FCM messages here. 

: 당신은 공식 웹 사이트의 예를 here 보면

+0

어디에서 보내고 있습니까? –

답변

2

은, 당신이 댓글을 볼 수 있습니다. 이 점을 이해하면 콜백을 트리거하기 위해 메시지에 데이터 구성 요소가 있어야한다는 것입니다. 이 코드를 기반으로 콜백이 트리거됩니다.

+0

하지만 보낸 메시지는 어떻게됩니까? 위 코드 샘플과 같은 메시지를 보낼 때 콜백 처리기 onMessageSent (String msgId)가 트리거되지 않는 이유는 무엇입니까? –

+1

죄송합니다. 질문을 잘못 읽었습니다. onMessagSent에 대해 OnMessageReceived를 읽었습니다. 자, 저는 제 대답이 어떤 식 으로든 도움이 될 것이라고 생각하지 않습니다. – NickT

+0

문제는 없습니다. 그럼에도 불구하고, 귀하의 의견에 감사드립니다. –

0

예, 문제가 해결되었습니다. google-services.json을 잘못된 폴더에 넣습니다. 다음 번에 더 많은 클라이언트를 구현하기 위해 "get started guide"을 따라야합니다.