Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM Android - null message ID

I've implemented my subclass of FirebaseMessagingService and I'm successfully receiving downstream messages in FirebaseMessagingService.onMessageReceived(RemoteMessage). My problem is that RemoteMessage.getMessageId() always returns null. From what I understood, message ID is mandatory and should be automatically generated by the FCM server. In fact, calling https://fcm.googleapis.com/fcm/send returns a message ID, I just cannot access it on the app side.

Is there something I am missing?

Here's my FCM messaging service class:

public class FcmMessagingService extends FirebaseMessagingService {
    private static final String TAG = "FcmMessagingService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Logg.d(TAG, "Received message; id: " + remoteMessage.getMessageId());
        Map<String, String> data = remoteMessage.getData();
        Logg.d(TAG, "Data: " + data);

        String message = data.get("message");
        /* ... */
    }
}
like image 901
SpaceBison Avatar asked Jun 24 '16 07:06

SpaceBison


People also ask

How do I find my FCM Sender ID?

Click the Cloud Messaging tab next to the General tab. The Project credentials section appears. The Project credentials section displays the Firebase Cloud Messaging token, Sender ID, and the Server key. Copy Sender ID.

What is FCM ID in Android?

Generating Firebase Cloud Messaging (FCM) Server Key and Sender ID for Android Devices. The first step in the installation and configuration of the sample Engagement application on an Android device is the generation of the sender ID. Android devices use the sender ID to register with FCM and receive notifications.

What is multicast ID in FCM?

The multicast_id is a required parameter in the FCM response payload, and is a unique ID that identifies the multicast message. A multicast message is a notification that will be sent from a server and targeting multiple client applications.

Is FCM ID unique?

The FCM Sender ID is a unique numerical value generated in the Google Developers Console / Google Cloud Console when configuring your projects. The project number is typically the FCM sender ID and is used during the registration process to identify an app server that can send messages to the client app.


1 Answers

As of Firebase Android SDK 9.4 this issue has been resolved

From the release notes:

FIXED RemoteMessage#getMessageId() now returns the correct message-id for received messages. Previously, it returned null.

Updating the com.google.firebase:firebase-messaging dependency to version 9.4.0 has indeed fixed the problem.


Update 2.07.2016: I was informed that this is indeed a bug and a fix will be included in the nearest release.


Turns out we cannot get message ID on the app side. I've asked the Firebase support for help and this is what they told me:

When FCM has successfully receives the request, it will attempt to deliver to all subscribed devices, FCM will return a response which includes messageID to your server. You cannot directly get MessageID on your client side (Android device). MessageID is a parameter in response payload.

As a workaround I am generating custom message identifiers on the server and passing them in the payload.

What RemoteMessage.getMessageId() actually does remains a mystery.

like image 133
SpaceBison Avatar answered Oct 10 '22 18:10

SpaceBison