Search code examples
androidgoogle-cloud-messagingmessagingappserver

FCM Server Implementation


for the server-sided implementation to support upstream and downstream messages via XMMP, I use org.jivesoftware.smack.tcp.XMPPTCPConnection. I migrated from GCM to FCM and now my app server does not receive any upstream messages anymore. Do I have to change host, port or something else to use FCM?

From Android client I send messages like:

String senderId = ctxt.getResources().getString(com.app.teamchannel.R.string.sender_id);

        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());

        Log.v(Constants.TAG, "verification message successfully sent: " + GcmConstants.ACTION_CHAT + " -> " + Constants.FLAG_NEW_CHAT);

Solution

  • Solved the problem. I put my google-services.json in the wrong folder. Now the communication between the endpoints from google cloud server and my app server works.