'I'm looking for detailed explanation on FCM push notification sending to Android device

Our backend is developed in Ruby on Rails and our clients are native iOS (swiftUI) and Android (Java). Our backend has a function where it need to send a push notification to a mobile device. For iOS we got all working perfect. For Android we've implemented the following class which seem to work correctly

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    SharedPreferences sharedPref;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        //showNotification(remoteMessage.getNotification().getBody());
        Log.e(TAG, "From: " + remoteMessage.getFrom());
        Log.e(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());

    }
    @Override
    public void onNewToken(String token) {
        Log.d(TAG, "Refreshed token: " + token);
        sendRegistrationToServer(token);
    }

    private void sendRegistrationToServer(String token) {
        Log.d("TOKEN ", token);
        sharedPref = this.getSharedPreferences(
                getString(R.string.preference_file_key), Context.MODE_PRIVATE);
        sharedPref.edit()
                .putString("aps_token", token)
                .apply();
        ApiServer.getInstance().sendToken(token);
    }
    

The server is receiving the token and links it to the device On server side in case it is Android we need to send an FCM notification to the token (not topics or groups). I've tried ruby gems fcm and fcmpush and I will always result in a senderId mismatch. I've tried doing it using CURL to post directly but without success.

I assume the problem lies in the area of the way google authenticates things with service accounts, json files etc.

Can anyone who cracked this before explain in detail the following:

  • which credentials (files, keys) to use from fireebase console on both server side and client side

Examples are highly appreciated



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source