Reputation: 3202
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");
/* ... */
}
}
Upvotes: 8
Views: 5443
Reputation: 3202
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 returnednull
.
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.
Upvotes: 13